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:
Alexis de Lattre
2023-11-29 16:51:15 +01:00
parent 5ad925cee1
commit 92a1b511c1
8 changed files with 134 additions and 4 deletions

View File

@@ -25,6 +25,8 @@ This module has been written by Alexis de Lattre from Akretion France.
'data': [
'views/stock_picking.xml',
'views/purchase_order.xml',
'views/stock_move.xml',
'views/stock_move_line.xml',
],
'installable': True,
}

View File

@@ -1 +1,3 @@
from . import purchase
from . import stock_move
from . import stock_move_line

View 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

View 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

View 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>

View 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>

View File

@@ -16,6 +16,9 @@
<field name="origin" position="after">
<field name="purchase_id" attrs="{'invisible': [('purchase_id', '=', False)]}"/>
</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>
</record>

View File

@@ -79,15 +79,21 @@ class PurchaseOrderLine(models.Model):
compute='_compute_product_supplier_code', string='Vendor Product Code')
def _compute_product_supplier_code(self):
pso = self.env['product.supplierinfo']
for line in self:
code = False
if not line.display_type and line.product_id and line.order_id:
partner_id = line.order_id.partner_id.commercial_partner_id.id
if partner_id:
for supplier_info in line.product_id.seller_ids:
if supplier_info.partner_id.id == partner_id:
code = supplier_info.product_code
break
sinfo = pso.search_read([
('product_code', '!=', False),
('partner_id', '=', partner_id),
('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
def _get_product_purchase_description(self, product_lang):