diff --git a/purchase.py b/purchase.py
index 3237c65..775fd3f 100644
--- a/purchase.py
+++ b/purchase.py
@@ -62,7 +62,39 @@ class Line(metaclass=PoolMeta):
address_equipment = fields.Many2One('party.address', "Direccion", required=True)
serial_equipment = fields.Char("Serial", size=None, required=True)
refurbish = fields.Boolean("Refurbish")
-
+ product_equipment = fields.Boolean("Product Equipment")
+
+ def on_change_product(self):
+ if not self.product:
+ self.product_equipment = False
+ return
+
+ party = None
+ if self.purchase:
+ party = self.purchase.invoice_party or self.purchase.party
+
+ # Set taxes before unit_price to have taxes in context of purchase
+ # price
+ self.taxes = self.compute_taxes(party)
+
+ category = self.product.purchase_uom.category
+ if not self.unit or self.unit.category != category:
+ self.unit = self.product.purchase_uom
+
+ product_suppliers = list(self.product.product_suppliers_used(
+ **self._get_product_supplier_pattern()))
+ if len(product_suppliers) == 1:
+ self.product_supplier, = product_suppliers
+ elif (self.product_supplier
+ and self.product_supplier not in product_suppliers):
+ self.product_supplier = None
+
+ self.unit_price = self.compute_unit_price()
+
+ self.type = 'line'
+ self.amount = self.on_change_with_amount()
+ self.product_equipment = True
+
def default_address_equipment():
pool = Pool()
Company = pool.get('company.company')
@@ -70,13 +102,10 @@ class Line(metaclass=PoolMeta):
if company:
company = Company(company)
return company.party.addresses[0].id
-
- """
+
@classmethod
def view_attributes(cls):
return super(Line, cls).view_attributes() + [
('//page[@id="equipment"]', 'states', {
- 'invisible': Eval('product.equipment'),
+ 'invisible': ~Eval('product_equipment', True),
})]
- """
-
diff --git a/view/purchase_line_form.xml b/view/purchase_line_form.xml
index 8f8c382..4edf093 100644
--- a/view/purchase_line_form.xml
+++ b/view/purchase_line_form.xml
@@ -14,4 +14,9 @@
+
+
+
+