Use fields.depends decorator
issue3487 review2301002
This commit is contained in:
+3
-2
@@ -31,7 +31,6 @@ class Template:
|
||||
'required': Eval('purchasable', False),
|
||||
},
|
||||
domain=[('category', '=', Eval('default_uom_category'))],
|
||||
on_change_with=['default_uom', 'purchase_uom', 'purchasable'],
|
||||
depends=['active', 'purchasable', 'default_uom_category'])
|
||||
|
||||
@classmethod
|
||||
@@ -52,6 +51,7 @@ class Template:
|
||||
if 'purchasable' not in cls.account_expense.depends:
|
||||
cls.account_expense.depends.append('purchasable')
|
||||
|
||||
@fields.depends('default_uom', 'purchase_uom', 'purchasable')
|
||||
def on_change_with_purchase_uom(self):
|
||||
if self.default_uom:
|
||||
if self.purchase_uom:
|
||||
@@ -148,7 +148,7 @@ class ProductSupplier(ModelSQL, ModelView):
|
||||
product = fields.Many2One('product.template', 'Product', required=True,
|
||||
ondelete='CASCADE', select=True)
|
||||
party = fields.Many2One('party.party', 'Supplier', required=True,
|
||||
ondelete='CASCADE', select=True, on_change=['party'])
|
||||
ondelete='CASCADE', select=True)
|
||||
name = fields.Char('Name', size=None, translate=True, select=True)
|
||||
code = fields.Char('Code', size=None, select=True)
|
||||
sequence = fields.Integer('Sequence')
|
||||
@@ -222,6 +222,7 @@ class ProductSupplier(ModelSQL, ModelView):
|
||||
company = Company(Transaction().context['company'])
|
||||
return company.currency.id
|
||||
|
||||
@fields.depends('party')
|
||||
def on_change_party(self):
|
||||
cursor = Transaction().cursor
|
||||
changes = {
|
||||
|
||||
+31
-25
@@ -62,11 +62,10 @@ class Purchase(Workflow, ModelSQL, ModelView):
|
||||
depends=['state'])
|
||||
payment_term = fields.Many2One('account.invoice.payment_term',
|
||||
'Payment Term', required=True, states=_STATES, depends=_DEPENDS)
|
||||
party = fields.Many2One('party.party', 'Party',
|
||||
required=True, states=_STATES, on_change=['party', 'payment_term'],
|
||||
select=True, depends=_DEPENDS)
|
||||
party_lang = fields.Function(fields.Char('Party Language',
|
||||
on_change_with=['party']), 'on_change_with_party_lang')
|
||||
party = fields.Many2One('party.party', 'Party', required=True,
|
||||
states=_STATES, select=True, depends=_DEPENDS)
|
||||
party_lang = fields.Function(fields.Char('Party Language'),
|
||||
'on_change_with_party_lang')
|
||||
invoice_address = fields.Many2One('party.address', 'Invoice Address',
|
||||
domain=[('party', '=', Eval('party'))], states=_STATES,
|
||||
depends=['state', 'party'])
|
||||
@@ -79,11 +78,10 @@ class Purchase(Workflow, ModelSQL, ModelView):
|
||||
| (Eval('lines', [0]) & Eval('currency'))),
|
||||
},
|
||||
depends=['state'])
|
||||
currency_digits = fields.Function(fields.Integer('Currency Digits',
|
||||
on_change_with=['currency']), 'on_change_with_currency_digits')
|
||||
currency_digits = fields.Function(fields.Integer('Currency Digits'),
|
||||
'on_change_with_currency_digits')
|
||||
lines = fields.One2Many('purchase.line', 'purchase', 'Lines',
|
||||
states=_STATES, on_change=['lines', 'currency', 'party'],
|
||||
depends=_DEPENDS)
|
||||
states=_STATES, depends=_DEPENDS)
|
||||
comment = fields.Text('Comment')
|
||||
untaxed_amount = fields.Function(fields.Numeric('Untaxed',
|
||||
digits=(16, Eval('currency_digits', 2)),
|
||||
@@ -299,6 +297,7 @@ class Purchase(Workflow, ModelSQL, ModelView):
|
||||
def default_shipment_state():
|
||||
return 'none'
|
||||
|
||||
@fields.depends('party', 'payment_term')
|
||||
def on_change_party(self):
|
||||
pool = Pool()
|
||||
PaymentTerm = pool.get('account.invoice.payment_term')
|
||||
@@ -347,11 +346,13 @@ class Purchase(Workflow, ModelSQL, ModelView):
|
||||
changes['payment_term']).rec_name
|
||||
return changes
|
||||
|
||||
@fields.depends('currency')
|
||||
def on_change_with_currency_digits(self, name=None):
|
||||
if self.currency:
|
||||
return self.currency.digits
|
||||
return 2
|
||||
|
||||
@fields.depends('party')
|
||||
def on_change_with_party_lang(self, name=None):
|
||||
Config = Pool().get('ir.configuration')
|
||||
if self.party:
|
||||
@@ -365,6 +366,7 @@ class Purchase(Workflow, ModelSQL, ModelView):
|
||||
context['language'] = self.party.lang.code
|
||||
return context
|
||||
|
||||
@fields.depends('lines', 'currency', 'party')
|
||||
def on_change_lines(self):
|
||||
pool = Pool()
|
||||
Tax = pool.get('account.tax')
|
||||
@@ -832,9 +834,7 @@ class PurchaseLine(ModelSQL, ModelView):
|
||||
'invisible': Eval('type') != 'line',
|
||||
'required': Eval('type') == 'line',
|
||||
'readonly': ~Eval('_parent_purchase'),
|
||||
}, on_change=['product', 'quantity', 'unit',
|
||||
'_parent_purchase.currency', '_parent_purchase.party',
|
||||
'_parent_purchase.purchase_date'],
|
||||
},
|
||||
depends=['unit_digits', 'type'])
|
||||
unit = fields.Many2One('product.uom', 'Unit',
|
||||
states={
|
||||
@@ -847,19 +847,15 @@ class PurchaseLine(ModelSQL, ModelView):
|
||||
('category', '=', Eval('product_uom_category')),
|
||||
('category', '!=', -1)),
|
||||
],
|
||||
on_change=['product', 'quantity', 'unit', '_parent_purchase.currency',
|
||||
'_parent_purchase.party'],
|
||||
depends=['product', 'type', 'product_uom_category'])
|
||||
unit_digits = fields.Function(fields.Integer('Unit Digits',
|
||||
on_change_with=['unit']), 'on_change_with_unit_digits')
|
||||
unit_digits = fields.Function(fields.Integer('Unit Digits'),
|
||||
'on_change_with_unit_digits')
|
||||
product = fields.Many2One('product.product', 'Product',
|
||||
domain=[('purchasable', '=', True)],
|
||||
states={
|
||||
'invisible': Eval('type') != 'line',
|
||||
'readonly': ~Eval('_parent_purchase'),
|
||||
}, on_change=['product', 'unit', 'quantity', 'description',
|
||||
'_parent_purchase.party', '_parent_purchase.currency',
|
||||
'_parent_purchase.purchase_date'],
|
||||
},
|
||||
context={
|
||||
'locations': If(Bool(Eval('_parent_purchase', {}).get(
|
||||
'warehouse')),
|
||||
@@ -870,8 +866,7 @@ class PurchaseLine(ModelSQL, ModelView):
|
||||
'stock_skip_warehouse': True,
|
||||
}, depends=['type'])
|
||||
product_uom_category = fields.Function(
|
||||
fields.Many2One('product.uom.category', 'Product Uom Category',
|
||||
on_change_with=['product']),
|
||||
fields.Many2One('product.uom.category', 'Product Uom Category'),
|
||||
'on_change_with_product_uom_category')
|
||||
unit_price = fields.Numeric('Unit Price', digits=(16, 4),
|
||||
states={
|
||||
@@ -884,8 +879,7 @@ class PurchaseLine(ModelSQL, ModelView):
|
||||
states={
|
||||
'invisible': ~Eval('type').in_(['line', 'subtotal']),
|
||||
'readonly': ~Eval('_parent_purchase'),
|
||||
}, on_change_with=['type', 'quantity', 'unit_price', 'unit',
|
||||
'_parent_purchase.currency'],
|
||||
},
|
||||
depends=['type']), 'get_amount')
|
||||
description = fields.Text('Description', size=None, required=True)
|
||||
note = fields.Text('Note')
|
||||
@@ -913,8 +907,6 @@ class PurchaseLine(ModelSQL, ModelView):
|
||||
to_location = fields.Function(fields.Many2One('stock.location',
|
||||
'To Location'), 'get_to_location')
|
||||
delivery_date = fields.Function(fields.Date('Delivery Date',
|
||||
on_change_with=['product', 'quantity',
|
||||
'_parent_purchase.purchase_date', '_parent_purchase.party'],
|
||||
states={
|
||||
'invisible': ((Eval('type') != 'line')
|
||||
| (If(Bool(Eval('quantity')), Eval('quantity', 0), 0)
|
||||
@@ -993,6 +985,7 @@ class PurchaseLine(ModelSQL, ModelView):
|
||||
return True
|
||||
return False
|
||||
|
||||
@fields.depends('unit')
|
||||
def on_change_with_unit_digits(self, name=None):
|
||||
if self.unit:
|
||||
return self.unit.digits
|
||||
@@ -1019,6 +1012,9 @@ class PurchaseLine(ModelSQL, ModelView):
|
||||
self.product.purchase_uom.id
|
||||
return context
|
||||
|
||||
@fields.depends('product', 'unit', 'quantity', 'description',
|
||||
'_parent_purchase.party', '_parent_purchase.currency',
|
||||
'_parent_purchase.purchase_date')
|
||||
def on_change_product(self):
|
||||
Product = Pool().get('product.product')
|
||||
|
||||
@@ -1069,10 +1065,14 @@ class PurchaseLine(ModelSQL, ModelView):
|
||||
res['amount'] = self.on_change_with_amount()
|
||||
return res
|
||||
|
||||
@fields.depends('product')
|
||||
def on_change_with_product_uom_category(self, name=None):
|
||||
if self.product:
|
||||
return self.product.default_uom_category.id
|
||||
|
||||
@fields.depends('product', 'quantity', 'unit',
|
||||
'_parent_purchase.currency', '_parent_purchase.party',
|
||||
'_parent_purchase.purchase_date')
|
||||
def on_change_quantity(self):
|
||||
Product = Pool().get('product.product')
|
||||
|
||||
@@ -1088,9 +1088,13 @@ class PurchaseLine(ModelSQL, ModelView):
|
||||
Decimal(1) / 10 ** self.__class__.unit_price.digits[1])
|
||||
return res
|
||||
|
||||
@fields.depends('product', 'quantity', 'unit',
|
||||
'_parent_purchase.currency', '_parent_purchase.party')
|
||||
def on_change_unit(self):
|
||||
return self.on_change_quantity()
|
||||
|
||||
@fields.depends('type', 'quantity', 'unit_price', 'unit',
|
||||
'_parent_purchase.currency')
|
||||
def on_change_with_amount(self):
|
||||
if self.type == 'line':
|
||||
currency = self.purchase.currency if self.purchase else None
|
||||
@@ -1131,6 +1135,8 @@ class PurchaseLine(ModelSQL, ModelView):
|
||||
else:
|
||||
return self.purchase.party.supplier_location.id
|
||||
|
||||
@fields.depends('product', 'quantity',
|
||||
'_parent_purchase.purchase_date', '_parent_purchase.party')
|
||||
def on_change_with_delivery_date(self, name=None):
|
||||
if (self.product
|
||||
and self.quantity > 0
|
||||
|
||||
@@ -165,8 +165,8 @@ class Move:
|
||||
'Purchase Currency', states={
|
||||
'invisible': ~Eval('purchase_visible', False),
|
||||
}, depends=['purchase_visible']), 'get_purchase_fields')
|
||||
purchase_visible = fields.Function(fields.Boolean('Purchase Visible',
|
||||
on_change_with=['from_location']), 'on_change_with_purchase_visible')
|
||||
purchase_visible = fields.Function(fields.Boolean('Purchase Visible'),
|
||||
'on_change_with_purchase_visible')
|
||||
supplier = fields.Function(fields.Many2One('party.party', 'Supplier'),
|
||||
'get_supplier', searcher='search_supplier')
|
||||
purchase_exception_state = fields.Function(fields.Selection([
|
||||
@@ -232,6 +232,7 @@ class Move:
|
||||
elif name[9:] == 'unit_digits':
|
||||
return 2
|
||||
|
||||
@fields.depends('from_location')
|
||||
def on_change_with_purchase_visible(self, name=None):
|
||||
if self.from_location:
|
||||
if self.from_location.type == 'supplier':
|
||||
|
||||
Reference in New Issue
Block a user