Compute name of the product for stock move

So we can customize the product name to use the customer or supplier name.

Closes #12893
This commit is contained in:
Cédric Krier
2024-01-04 23:54:49 +01:00
parent b4608428fb
commit a8ee857681
6 changed files with 39 additions and 3 deletions
+11
View File
@@ -7,6 +7,7 @@ from trytond.model import ModelView, Workflow, fields
from trytond.model.exceptions import AccessError
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval
from trytond.tools import cached_property
from trytond.transaction import Transaction, without_check_access
@@ -186,6 +187,16 @@ class Move(metaclass=PoolMeta):
if isinstance(self.origin, PurchaseLine):
return self.origin.purchase.party.id
@cached_property
def product_name(self):
pool = Pool()
PurchaseLine = pool.get('purchase.line')
name = super().product_name
if (isinstance(self.origin, PurchaseLine)
and self.origin.product_supplier):
name = self.origin.product_supplier.rec_name
return name
@fields.depends('origin')
def on_change_with_product_uom_category(self, name=None):
pool = Pool()
+2 -1
View File
@@ -3,7 +3,7 @@
from trytond.pool import Pool
from . import account, product, sale
from . import account, product, sale, stock
__all__ = ['register']
@@ -15,6 +15,7 @@ def register():
product.ProductCustomer,
sale.Line,
account.InvoiceLine,
stock.Move,
module='sale_product_customer', type_='model')
Pool.register(
sale.AmendmentLine,
+19
View File
@@ -0,0 +1,19 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.pool import Pool, PoolMeta
from trytond.tools import cached_property
class Move(metaclass=PoolMeta):
__name__ = 'stock.move'
@cached_property
def product_name(self):
pool = Pool()
SaleLine = pool.get('sale.line')
name = super().product_name
if (isinstance(self.origin, SaleLine)
and self.origin.product_customer):
name = self.origin.product_customer.rec_name
return name
+1
View File
@@ -5,6 +5,7 @@ depends:
ir
product
sale
stock
extras_depend:
sale_amendment
sale_blanket_agreement
+1 -1
View File
@@ -520,7 +520,7 @@
</table:table-row>
<table:table-row>
<table:table-cell table:style-name="Table1.A3" office:value-type="string">
<text:p text:style-name="P13"><text:placeholder text:placeholder-type="text">&lt;move.product.rec_name&gt;</text:placeholder></text:p>
<text:p text:style-name="P13"><text:placeholder text:placeholder-type="text">&lt;move.product_name&gt;</text:placeholder></text:p>
</table:table-cell>
<table:table-cell table:style-name="Table1.B3" office:value-type="string">
<text:p text:style-name="P12"><text:placeholder text:placeholder-type="text">&lt;format_number_symbol(move.quantity, shipment.delivery_address.party.lang, move.unit, digits=move.unit.digits)&gt;</text:placeholder></text:p>
+5 -1
View File
@@ -19,7 +19,7 @@ from trytond.model.exceptions import AccessError
from trytond.modules.product import price_digits, round_price
from trytond.pool import Pool
from trytond.pyson import Bool, Eval, If, TimeDelta
from trytond.tools import grouped_slice, reduce_ids
from trytond.tools import cached_property, grouped_slice, reduce_ids
from trytond.transaction import Transaction, without_check_access
from .exceptions import MoveFutureWarning, MoveOriginWarning
@@ -471,6 +471,10 @@ class Move(Workflow, ModelSQL, ModelView):
or self.unit.category != default_uom.category):
self.unit = default_uom
@cached_property
def product_name(self):
return self.product.rec_name if self.product else ''
@fields.depends('product')
def on_change_with_product_uom_category(self, name=None):
return self.product.default_uom_category if self.product else None