tab 'equipment' in sale invisible with product
This commit is contained in:
parent
0566d0d66f
commit
0931aa7727
@ -33,6 +33,8 @@ class OpticalEquipment(ModelSQL, ModelView):
|
||||
'equipment','subscription', "Subscriptions",
|
||||
states={'readonly': True})
|
||||
|
||||
current_subscription = fields.Many2One('sale.subscription')
|
||||
|
||||
@staticmethod
|
||||
def get_origin():
|
||||
return None
|
||||
|
63
sale.py
63
sale.py
@ -1,6 +1,8 @@
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.model import ModelView, ModelSQL, fields
|
||||
from trytond.pyson import Eval, Bool, If
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
|
||||
class SaleLine(metaclass=PoolMeta):
|
||||
@ -8,6 +10,65 @@ class SaleLine(metaclass=PoolMeta):
|
||||
__name__ = 'sale.line'
|
||||
|
||||
address_equipment = fields.Many2One('party.address', "Direccion")
|
||||
product_equipment = fields.Boolean("Product Equipment")
|
||||
unit_digits = fields.Function(fields.Integer('Unit Digits'),
|
||||
'on_change_with_unit_digits')
|
||||
|
||||
|
||||
def on_change_with_unit_digits(self, name=None):
|
||||
if self.unit:
|
||||
return self.unit.digits
|
||||
return 2
|
||||
|
||||
@fields.depends('product', 'unit', 'quantity', 'sale',
|
||||
'_parent_sale.party',
|
||||
methods=['_get_tax_rule_pattern', '_get_context_sale_price',
|
||||
'on_change_with_amount'])
|
||||
def on_change_product(self):
|
||||
Product = Pool().get('product.product')
|
||||
if not self.product:
|
||||
self.product_equipment = False
|
||||
return
|
||||
|
||||
party = None
|
||||
|
||||
if self.sale and self.sale.party:
|
||||
self.product_equipment = False
|
||||
party = self.sale.party
|
||||
|
||||
# Set taxes before unit_price to have taxes in context of sale price
|
||||
taxes = []
|
||||
pattern = self._get_tax_rule_pattern()
|
||||
for tax in self.product.customer_taxes_used:
|
||||
if party and party.customer_tax_rule:
|
||||
tax_ids = party.customer_tax_rule.apply(tax, pattern)
|
||||
if tax_ids:
|
||||
taxes.extend(tax_ids)
|
||||
continue
|
||||
taxes.append(tax.id)
|
||||
|
||||
if party and party.customer_tax_rule:
|
||||
tax_ids = party.customer_tax_rule.apply(None, pattern)
|
||||
if tax_ids:
|
||||
taxes.extend(tax_ids)
|
||||
self.taxes = taxes
|
||||
|
||||
category = self.product.sale_uom.category
|
||||
if not self.unit or self.unit.category != category:
|
||||
self.unit = self.product.sale_uom
|
||||
self.unit_digits = self.product.sale_uom.digits
|
||||
|
||||
with Transaction().set_context(self._get_context_sale_price()):
|
||||
self.unit_price = Product.get_sale_price([self.product],
|
||||
self.quantity or 0)[self.product.id]
|
||||
|
||||
if self.unit_price:
|
||||
self.unit_price = self.unit_price.quantize(
|
||||
Decimal(1) / 10 ** self.__class__.unit_price.digits[1])
|
||||
|
||||
self.type = 'line'
|
||||
self.amount = self.on_change_with_amount()
|
||||
self.product_equipment = True
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@ -24,7 +85,7 @@ class SaleLine(metaclass=PoolMeta):
|
||||
def view_attributes(cls):
|
||||
return super(SaleLine, cls).view_attributes() + [
|
||||
('//page[@id="equipment"]', 'states', {
|
||||
'invisible': ~Eval('lines.product.equipment'),
|
||||
'invisible': ~Eval('product_equipment', True),
|
||||
})]
|
||||
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<field name="biomedical_class"/>
|
||||
<label name="calibration"/>
|
||||
<field name="calibration"/>
|
||||
<newline/>
|
||||
<label name="mark_category"/>
|
||||
<field name="mark_category"/>
|
||||
<label name="model_category"/>
|
||||
@ -38,6 +39,8 @@
|
||||
<field name="health_register"/>
|
||||
<label name="origin_country"/>
|
||||
<field name="origin_country"/>
|
||||
<label name="current_subscription"/>
|
||||
<field name="current_subscription"/>
|
||||
|
||||
<notebook>
|
||||
<page string="Subscriptions" id="subscriptions_equipment">
|
||||
|
@ -8,4 +8,9 @@
|
||||
<field name="address_equipment"/>
|
||||
</page>
|
||||
</xpath>
|
||||
<xpath
|
||||
expr="/form/notebook/page[@id='general']/field[@name='product']" position="after">
|
||||
<label name="product_equipment"/>
|
||||
<field name="product_equipment"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
Loading…
Reference in New Issue
Block a user