Compute name of the product for sale, purchase and invoice lines
Instead of having the code in the report templates, we use a property that can be extended without updating the template. Closes #12892
This commit is contained in:
1 parent
bd54284d6f
commit
b4608428fb
12 files changed
+82
-23
No files matched your search
@@ -818,8 +818,8 @@
|
||||
</table:table-row>
|
||||
<table:table-row>
|
||||
<table:table-cell table:style-name="Table1.A5" office:value-type="string">
|
||||
<text:p text:style-name="Table_20_Contents"><text:placeholder text:placeholder-type="text"><if test="line.product"></text:placeholder></text:p>
|
||||
<text:p text:style-name="Table_20_Contents"><text:placeholder text:placeholder-type="text"><line.product.rec_name></text:placeholder></text:p>
|
||||
<text:p text:style-name="Table_20_Contents"><text:placeholder text:placeholder-type="text"><if test="line.product_name"></text:placeholder></text:p>
|
||||
<text:p text:style-name="Table_20_Contents"><text:placeholder text:placeholder-type="text"><line.product_name></text:placeholder></text:p>
|
||||
<text:p text:style-name="Table_20_Contents"><text:placeholder text:placeholder-type="text"></if></text:placeholder></text:p>
|
||||
<text:p text:style-name="Table_20_Contents"><text:placeholder text:placeholder-type="text"><if test="line.description"></text:placeholder></text:p>
|
||||
<text:p text:style-name="Table_20_Contents"><text:placeholder text:placeholder-type="text"><for each="description in line.description.split('\n')"></text:placeholder></text:p>
|
||||
|
||||
@@ -29,7 +29,8 @@ from trytond.pool import Pool
|
||||
from trytond.pyson import Bool, Eval, Id, If
|
||||
from trytond.report import Report
|
||||
from trytond.rpc import RPC
|
||||
from trytond.tools import firstline, grouped_slice, reduce_ids, slugify
|
||||
from trytond.tools import (
|
||||
cached_property, firstline, grouped_slice, reduce_ids, slugify)
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.wizard import (
|
||||
Button, StateAction, StateReport, StateTransition, StateView, Wizard)
|
||||
@@ -2636,6 +2637,10 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
|
||||
if not self.unit or self.unit.category != category:
|
||||
self.unit = self.product.default_uom.id
|
||||
|
||||
@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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -110,6 +111,16 @@ class InvoiceLine(metaclass=PoolMeta):
|
||||
('type', '=', Eval('type')),
|
||||
]
|
||||
|
||||
@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()
|
||||
|
||||
@@ -707,14 +707,9 @@
|
||||
</table:table-row>
|
||||
<table:table-row>
|
||||
<table:table-cell table:style-name="Table1.A5" office:value-type="string">
|
||||
<text:p text:style-name="P26"><text:placeholder text:placeholder-type="text"><choose></text:placeholder></text:p>
|
||||
<text:p text:style-name="P26"><text:placeholder text:placeholder-type="text"><when test="line.product_supplier"></text:placeholder></text:p>
|
||||
<text:p text:style-name="P25"><text:placeholder text:placeholder-type="text"><line.product_supplier.rec_name></text:placeholder></text:p>
|
||||
<text:p text:style-name="P25"><text:placeholder text:placeholder-type="text"></when></text:placeholder></text:p>
|
||||
<text:p text:style-name="P25"><text:placeholder text:placeholder-type="text"><when test="line.product"></text:placeholder></text:p>
|
||||
<text:p text:style-name="P25"><text:placeholder text:placeholder-type="text"><line.product.rec_name></text:placeholder></text:p>
|
||||
<text:p text:style-name="P25"><text:placeholder text:placeholder-type="text"></when></text:placeholder></text:p>
|
||||
<text:p text:style-name="P25"><text:placeholder text:placeholder-type="text"></choose></text:placeholder></text:p>
|
||||
<text:p text:style-name="P25"><text:placeholder text:placeholder-type="text"><if test="line.product_name"></text:placeholder></text:p>
|
||||
<text:p text:style-name="P25"><text:placeholder text:placeholder-type="text"><line.product_name></text:placeholder></text:p>
|
||||
<text:p text:style-name="P25"><text:placeholder text:placeholder-type="text"></if></text:placeholder></text:p>
|
||||
<text:p text:style-name="P25"><text:placeholder text:placeholder-type="text"><if test="line.description"></text:placeholder></text:p>
|
||||
<text:p text:style-name="P25"><text:placeholder text:placeholder-type="text"><for each="description in line.description.split('\n')"></text:placeholder></text:p>
|
||||
<text:p text:style-name="P25"><text:placeholder text:placeholder-type="text"><description></text:placeholder></text:p>
|
||||
|
||||
@@ -25,7 +25,7 @@ from trytond.modules.currency.fields import Monetary
|
||||
from trytond.modules.product import price_digits
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Bool, Eval, If, PYSONEncoder
|
||||
from trytond.tools import firstline
|
||||
from trytond.tools import cached_property, firstline
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.wizard import (
|
||||
Button, StateAction, StateTransition, StateView, Wizard)
|
||||
@@ -1467,6 +1467,15 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
|
||||
|
||||
self.amount = self.on_change_with_amount()
|
||||
|
||||
@cached_property
|
||||
def product_name(self):
|
||||
if self.product_supplier:
|
||||
return self.product_supplier.rec_name
|
||||
elif self.product:
|
||||
return self.product.rec_name
|
||||
else:
|
||||
return ''
|
||||
|
||||
@fields.depends(
|
||||
'type', 'product',
|
||||
methods=['on_change_with_company', '_get_tax_rule_pattern'])
|
||||
|
||||
@@ -698,8 +698,8 @@
|
||||
</table:table-row>
|
||||
<table:table-row>
|
||||
<table:table-cell table:style-name="Table1.A5" office:value-type="string">
|
||||
<text:p text:style-name="P20"><text:placeholder text:placeholder-type="text"><if test="line.product"></text:placeholder></text:p>
|
||||
<text:p text:style-name="P20"><text:placeholder text:placeholder-type="text"><line.product.rec_name></text:placeholder></text:p>
|
||||
<text:p text:style-name="P20"><text:placeholder text:placeholder-type="text"><if test="line.product_name"></text:placeholder></text:p>
|
||||
<text:p text:style-name="P20"><text:placeholder text:placeholder-type="text"><line.product_name></text:placeholder></text:p>
|
||||
<text:p text:style-name="P20"><text:placeholder text:placeholder-type="text"></if></text:placeholder></text:p>
|
||||
<text:p text:style-name="P20"><text:placeholder text:placeholder-type="text"><if test="line.description"></text:placeholder></text:p>
|
||||
<text:p text:style-name="P20"><text:placeholder text:placeholder-type="text"><for each="description in line.description.split('\n')"></text:placeholder></text:p>
|
||||
|
||||
@@ -25,7 +25,7 @@ from trytond.modules.currency.fields import Monetary
|
||||
from trytond.modules.product import price_digits
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Bool, Eval, If, PYSONEncoder
|
||||
from trytond.tools import firstline, sortable_values
|
||||
from trytond.tools import cached_property, firstline, sortable_values
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.wizard import (
|
||||
Button, StateAction, StateTransition, StateView, Wizard)
|
||||
@@ -1550,6 +1550,10 @@ class SaleLine(TaxableMixin, sequence_ordered(), ModelSQL, ModelView):
|
||||
|
||||
self.amount = self.on_change_with_amount()
|
||||
|
||||
@cached_property
|
||||
def product_name(self):
|
||||
return self.product.rec_name if self.product else ''
|
||||
|
||||
@fields.depends(
|
||||
'type', 'product',
|
||||
methods=['on_change_with_company', '_get_tax_rule_pattern'])
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
from trytond.pool import Pool
|
||||
|
||||
from . import product, sale
|
||||
from . import account, product, sale
|
||||
|
||||
__all__ = ['register']
|
||||
|
||||
@@ -14,6 +14,7 @@ def register():
|
||||
product.Product,
|
||||
product.ProductCustomer,
|
||||
sale.Line,
|
||||
account.InvoiceLine,
|
||||
module='sale_product_customer', type_='model')
|
||||
Pool.register(
|
||||
sale.AmendmentLine,
|
||||
|
||||
@@ -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 InvoiceLine(metaclass=PoolMeta):
|
||||
__name__ = 'account.invoice.line'
|
||||
|
||||
@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
|
||||
@@ -52,14 +52,20 @@ class ProductCustomer(
|
||||
self.template = self.product.template
|
||||
|
||||
def get_rec_name(self, name):
|
||||
if self.name:
|
||||
name = self.name
|
||||
elif self.product:
|
||||
name = self.product.name
|
||||
if not self.name and not self.code:
|
||||
if self.product:
|
||||
name = self.product.rec_name
|
||||
else:
|
||||
name = self.template.rec_name
|
||||
else:
|
||||
name = self.template.name
|
||||
if self.code:
|
||||
name = '[' + self.code + '] ' + name
|
||||
if self.name:
|
||||
name = self.name
|
||||
elif self.product:
|
||||
name = self.product.name
|
||||
else:
|
||||
name = self.template.name
|
||||
if self.code:
|
||||
name = '[' + self.code + '] ' + name
|
||||
return name
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
from trytond.model import fields
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.pyson import Bool, Eval, If
|
||||
from trytond.tools import cached_property
|
||||
|
||||
|
||||
class Line(metaclass=PoolMeta):
|
||||
@@ -62,6 +63,13 @@ class Line(metaclass=PoolMeta):
|
||||
self.product, = self.product_customer.template.products
|
||||
self.on_change_product()
|
||||
|
||||
@cached_property
|
||||
def product_name(self):
|
||||
name = super().product_name
|
||||
if self.product_customer:
|
||||
name = self.product_customer.rec_name
|
||||
return name
|
||||
|
||||
|
||||
class AmendmentLine(metaclass=PoolMeta):
|
||||
__name__ = 'sale.amendment.line'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
[tryton]
|
||||
version=7.1.0
|
||||
depends:
|
||||
account_invoice
|
||||
ir
|
||||
product
|
||||
sale
|
||||
|
||||
Reference in new issue
Block a user