diff --git a/purchase.py b/purchase.py index f254993..625a035 100644 --- a/purchase.py +++ b/purchase.py @@ -3,6 +3,7 @@ from trytond.pool import Pool, PoolMeta from trytond.model import ( ModelView, ModelSQL, Workflow, fields) +from trytond.modules.product import price_digits, round_price from trytond.pyson import Eval, If, Bool from trytond.exceptions import UserError from trytond.i18n import gettext @@ -60,7 +61,7 @@ class Purchase(metaclass=PoolMeta): refurbish=line.refurbish, serial=None if line.quantity > 1 else line.serial_equipment, health_register=line.health_register, - software_version=line.software_version, + software_version=line.product.software_version, maintenance_frequency="none") equipment.save() else: @@ -96,6 +97,24 @@ class Line(metaclass=PoolMeta): company = Company(company) return company.party.addresses[0].id + @fields.depends( + 'product', 'quantity', methods=['_get_context_purchase_price']) + def on_change_quantity(self): + Product = Pool().get('product.product') + if self.quantity > 1 or self.quantity < 1: + self.serial_equipment = None + + if not self.product: + self.serial_equipment = None + return + + with Transaction().set_context(self._get_context_purchase_price()): + self.unit_price = Product.get_purchase_price([self.product], + abs(self.quantity or 0))[self.product.id] + + if self.unit_price: + self.unit_price = round_price(self.unit_price) + def on_change_product(self): if not self.product: self.product_equipment = False