fields change product in purchase

This commit is contained in:
sinergia 2022-08-02 21:28:03 -05:00
parent f7740e3827
commit 3c3e38e7fa

View File

@ -3,6 +3,7 @@
from trytond.pool import Pool, PoolMeta from trytond.pool import Pool, PoolMeta
from trytond.model import ( from trytond.model import (
ModelView, ModelSQL, Workflow, fields) ModelView, ModelSQL, Workflow, fields)
from trytond.modules.product import price_digits, round_price
from trytond.pyson import Eval, If, Bool from trytond.pyson import Eval, If, Bool
from trytond.exceptions import UserError from trytond.exceptions import UserError
from trytond.i18n import gettext from trytond.i18n import gettext
@ -60,7 +61,7 @@ class Purchase(metaclass=PoolMeta):
refurbish=line.refurbish, refurbish=line.refurbish,
serial=None if line.quantity > 1 else line.serial_equipment, serial=None if line.quantity > 1 else line.serial_equipment,
health_register=line.health_register, health_register=line.health_register,
software_version=line.software_version, software_version=line.product.software_version,
maintenance_frequency="none") maintenance_frequency="none")
equipment.save() equipment.save()
else: else:
@ -96,6 +97,24 @@ class Line(metaclass=PoolMeta):
company = Company(company) company = Company(company)
return company.party.addresses[0].id 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): def on_change_product(self):
if not self.product: if not self.product:
self.product_equipment = False self.product_equipment = False