purchase_stock_usability: add product_supplier_code in tree view of stock.move and stock.move.line
purchase_usability: improve computation of product_supplier_code on purchase order line
This commit is contained in:
@@ -25,6 +25,8 @@ This module has been written by Alexis de Lattre from Akretion France.
|
|||||||
'data': [
|
'data': [
|
||||||
'views/stock_picking.xml',
|
'views/stock_picking.xml',
|
||||||
'views/purchase_order.xml',
|
'views/purchase_order.xml',
|
||||||
|
'views/stock_move.xml',
|
||||||
|
'views/stock_move_line.xml',
|
||||||
],
|
],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
from . import purchase
|
from . import purchase
|
||||||
|
from . import stock_move
|
||||||
|
from . import stock_move_line
|
||||||
|
|||||||
32
purchase_stock_usability/models/stock_move.py
Normal file
32
purchase_stock_usability/models/stock_move.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# Copyright 2023 Akretion France (http://www.akretion.com)
|
||||||
|
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class StockMove(models.Model):
|
||||||
|
_inherit = 'stock.move'
|
||||||
|
|
||||||
|
# for optional display in tree view
|
||||||
|
product_supplier_code = fields.Char(
|
||||||
|
compute='_compute_product_supplier_code', string="Vendor Product Code")
|
||||||
|
|
||||||
|
def _compute_product_supplier_code(self):
|
||||||
|
pso = self.env['product.supplierinfo']
|
||||||
|
for move in self:
|
||||||
|
code = False
|
||||||
|
if move.purchase_line_id and move.purchase_line_id.order_id:
|
||||||
|
po = move.purchase_line_id.order_id
|
||||||
|
partner_id = po.partner_id.commercial_partner_id.id
|
||||||
|
if partner_id:
|
||||||
|
sinfo = pso.search_read([
|
||||||
|
('product_code', '!=', False),
|
||||||
|
('partner_id', '=', partner_id),
|
||||||
|
('company_id', 'in', (False, move.company_id.id)),
|
||||||
|
('product_id', 'in', (False, move.product_id.id)),
|
||||||
|
], ['product_code'], limit=1, order='product_id')
|
||||||
|
# if I order by product_id, I get the null values at the end
|
||||||
|
if sinfo:
|
||||||
|
code = sinfo[0]['product_code']
|
||||||
|
move.product_supplier_code = code
|
||||||
33
purchase_stock_usability/models/stock_move_line.py
Normal file
33
purchase_stock_usability/models/stock_move_line.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Copyright 2023 Akretion France (http://www.akretion.com)
|
||||||
|
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class StockMoveLine(models.Model):
|
||||||
|
_inherit = 'stock.move.line'
|
||||||
|
|
||||||
|
# for optional display in tree view
|
||||||
|
product_supplier_code = fields.Char(
|
||||||
|
compute='_compute_product_supplier_code', string="Vendor Product Code")
|
||||||
|
|
||||||
|
def _compute_product_supplier_code(self):
|
||||||
|
pso = self.env['product.supplierinfo']
|
||||||
|
for mline in self:
|
||||||
|
code = False
|
||||||
|
move = mline.move_id
|
||||||
|
if move and move.purchase_line_id and move.purchase_line_id.order_id:
|
||||||
|
po = move.purchase_line_id.order_id
|
||||||
|
partner_id = po.partner_id.commercial_partner_id.id
|
||||||
|
if partner_id:
|
||||||
|
sinfo = pso.search_read([
|
||||||
|
('product_code', '!=', False),
|
||||||
|
('partner_id', '=', partner_id),
|
||||||
|
('company_id', 'in', (False, mline.company_id.id)),
|
||||||
|
('product_id', 'in', (False, mline.product_id.id)),
|
||||||
|
], ['product_code'], limit=1, order='product_id')
|
||||||
|
# if I order by product_id, I get the null values at the end
|
||||||
|
if sinfo:
|
||||||
|
code = sinfo[0]['product_code']
|
||||||
|
mline.product_supplier_code = code
|
||||||
21
purchase_stock_usability/views/stock_move.xml
Normal file
21
purchase_stock_usability/views/stock_move.xml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright 2023 Akretion France (http://www.akretion.com/)
|
||||||
|
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
-->
|
||||||
|
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="view_move_tree" model="ir.ui.view">
|
||||||
|
<field name="model">stock.move</field>
|
||||||
|
<field name="inherit_id" ref="stock.view_move_tree" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<!-- picking.purchase_id is a native field ; it is added to the picking form view in this module -->
|
||||||
|
<field name="product_id" position="after">
|
||||||
|
<field name="product_supplier_code" optional="hide" attrs="{'column_invisible': [('parent.purchase_id', '=', False)]}"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
31
purchase_stock_usability/views/stock_move_line.xml
Normal file
31
purchase_stock_usability/views/stock_move_line.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright 2023 Akretion France (http://www.akretion.com/)
|
||||||
|
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
-->
|
||||||
|
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="view_move_line_tree" model="ir.ui.view">
|
||||||
|
<field name="model">stock.move.line</field>
|
||||||
|
<field name="inherit_id" ref="stock.view_move_line_tree" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="product_id" position="after">
|
||||||
|
<field name="product_supplier_code" optional="hide"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<!-- View embedded in picking -->
|
||||||
|
<record id="view_stock_move_line_detailed_operation_tree" model="ir.ui.view">
|
||||||
|
<field name="model">stock.move.line</field>
|
||||||
|
<field name="inherit_id" ref="stock.view_stock_move_line_detailed_operation_tree" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="product_id" position="after">
|
||||||
|
<field name="product_supplier_code" optional="hide" attrs="{'column_invisible': [('parent.purchase_id', '=', False)]}"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
@@ -16,6 +16,9 @@
|
|||||||
<field name="origin" position="after">
|
<field name="origin" position="after">
|
||||||
<field name="purchase_id" attrs="{'invisible': [('purchase_id', '=', False)]}"/>
|
<field name="purchase_id" attrs="{'invisible': [('purchase_id', '=', False)]}"/>
|
||||||
</field>
|
</field>
|
||||||
|
<xpath expr="//field[@name='move_ids_without_package']/tree/field[@name='product_id']" position="after">
|
||||||
|
<field name="product_supplier_code" optional="hide" attrs="{'column_invisible': [('parent.purchase_id', '=', False)]}"/>
|
||||||
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|||||||
@@ -79,15 +79,21 @@ class PurchaseOrderLine(models.Model):
|
|||||||
compute='_compute_product_supplier_code', string='Vendor Product Code')
|
compute='_compute_product_supplier_code', string='Vendor Product Code')
|
||||||
|
|
||||||
def _compute_product_supplier_code(self):
|
def _compute_product_supplier_code(self):
|
||||||
|
pso = self.env['product.supplierinfo']
|
||||||
for line in self:
|
for line in self:
|
||||||
code = False
|
code = False
|
||||||
if not line.display_type and line.product_id and line.order_id:
|
if not line.display_type and line.product_id and line.order_id:
|
||||||
partner_id = line.order_id.partner_id.commercial_partner_id.id
|
partner_id = line.order_id.partner_id.commercial_partner_id.id
|
||||||
if partner_id:
|
if partner_id:
|
||||||
for supplier_info in line.product_id.seller_ids:
|
sinfo = pso.search_read([
|
||||||
if supplier_info.partner_id.id == partner_id:
|
('product_code', '!=', False),
|
||||||
code = supplier_info.product_code
|
('partner_id', '=', partner_id),
|
||||||
break
|
('company_id', 'in', (False, line.order_id.company_id.id)),
|
||||||
|
('product_id', 'in', (False, line.product_id.id)),
|
||||||
|
], ['product_code'], limit=1, order='product_id')
|
||||||
|
# if I order by product_id, I get the null values at the end
|
||||||
|
if sinfo:
|
||||||
|
code = sinfo[0]['product_code']
|
||||||
line.product_supplier_code = code
|
line.product_supplier_code = code
|
||||||
|
|
||||||
def _get_product_purchase_description(self, product_lang):
|
def _get_product_purchase_description(self, product_lang):
|
||||||
|
|||||||
Reference in New Issue
Block a user