Update on_change and on_change_with field depends | #157053

This commit is contained in:
Jared Esparza 2023-05-17 13:58:07 +02:00
parent 285a6063f7
commit 7d0367eca0
4 changed files with 18 additions and 8 deletions

View File

@ -4,6 +4,7 @@
from trytond.pool import Pool
from . import configuration
from . import sale
from . import sale_discount
def register():
@ -13,3 +14,6 @@ def register():
sale.Sale,
sale.SaleLine,
module='sale_margin', type_='model')
Pool.register(
sale_discount.SaleLine,
module='sale_margin', type_='model', depends=['sale_discount'])

View File

@ -98,13 +98,6 @@ class SaleLine(metaclass=PoolMeta):
'invisible': ~Eval('type').in_(['line', 'subtotal']),
}, depends=['type']), 'on_change_with_margin_percent')
@classmethod
def __setup__(cls):
super(SaleLine, cls).__setup__()
if hasattr(cls, 'gross_unit_price'):
cls.margin.on_change_with.add('gross_unit_price')
cls.margin_percent.on_change_with.add('gross_unit_price')
@staticmethod
def default_cost_price():
return _ZERO

13
sale_discount.py Normal file
View File

@ -0,0 +1,13 @@
from trytond.pool import PoolMeta
from trytond.model import fields
class SaleLine(metaclass=PoolMeta):
__name__ = 'sale.line'
@fields.depends('gross_unit_price')
def on_change_with_margin(self, name=None):
return super().on_change_with_margin(name)
@fields.depends('gross_unit_price')
def on_change_with_margin_percent(self, name=None):
return super().on_change_with_margin_percent(name)

View File

@ -9,6 +9,6 @@ from trytond.tests.test_tryton import ModuleTestCase
class SaleMarginTestCase(CompanyTestMixin, ModuleTestCase):
'Test SaleMargin module'
module = 'sale_margin'
extras = ['sale_discount']
del ModuleTestCase