Create contract

This commit is contained in:
2026-05-10 16:00:38 +02:00
parent 8e890f3c43
commit fe3a3ea71e
5 changed files with 184 additions and 31 deletions

View File

@@ -3576,7 +3576,9 @@ class ContractDetail(ModelView):
qt_unit = fields.Many2One('product.uom',"Unit")
tol_min = fields.Numeric("Tol - in %", required=True)
tol_max = fields.Numeric("Tol + in %", required=True)
crop = fields.Many2One('purchase.crop',"Crop")
crop = fields.Many2One(
'purchase.crop', "Crop",
states={'invisible': Eval('company_visible')})
del_period = fields.Many2One('product.month',"Delivery Period")
from_del = fields.Date("From")
to_del = fields.Date("To")
@@ -3594,12 +3596,13 @@ class ContractDetail(ModelView):
to_location = fields.Many2One(
'stock.location', "To location",
domain=[('type', 'in', ['storage', 'customer'])])
payment_term = fields.Many2One('account.invoice.payment_term',"Payment Term", required=True)
@classmethod
def default_category(cls):
lqt = cls._get_lqt_from_context()
if lqt and lqt.lot_p:
payment_term = fields.Many2One('account.invoice.payment_term',"Payment Term", required=True)
company_visible = fields.Boolean("Visible")
@classmethod
def default_category(cls):
lqt = cls._get_lqt_from_context()
if lqt and lqt.lot_p:
return 1
else:
return 2
@@ -3622,8 +3625,17 @@ class ContractDetail(ModelView):
return result
@classmethod
def default_price_type(cls):
return 'priced'
def default_price_type(cls):
return 'priced'
@classmethod
def default_company_visible(cls):
Company = Pool().get('company.company')
company_id = Transaction().context.get('company')
if not company_id:
return False
company = Company(company_id)
return bool(company.party and company.party.name == 'MELYA')
@classmethod
def _get_lqt_from_context(cls):
@@ -3684,14 +3696,35 @@ class ContractDetail(ModelView):
return getattr(lqt.lot_p.line.purchase if lqt.lot_p else lqt.lot_s.sale_line.sale, 'tol_max', None) if lqt else None
@classmethod
def default_del_period(cls):
lqt = cls._get_lqt_from_context()
if lqt and getattr(lqt.lot_p.line.purchase if lqt.lot_p else lqt.lot_s.sale_line.sale, 'del_period', None):
return lqt.lot_p.line.purchase.del_period.id if lqt.lot_p else lqt.lot_s.sale_line.sale.del_period.id
@fields.depends('del_period')
def on_change_del_period(self):
if self.del_period:
self.from_del = self.del_period.beg_date
def default_del_period(cls):
lqt = cls._get_lqt_from_context()
if lqt and getattr(lqt.lot_p.line.purchase if lqt.lot_p else lqt.lot_s.sale_line.sale, 'del_period', None):
return lqt.lot_p.line.purchase.del_period.id if lqt.lot_p else lqt.lot_s.sale_line.sale.del_period.id
@classmethod
def _get_base_contract(cls):
lqt = cls._get_lqt_from_context()
if lqt and lqt.lot_p:
return lqt.lot_p.line.purchase, 'Sale'
if lqt and lqt.lot_s:
return lqt.lot_s.sale_line.sale, 'Purchase'
return None, None
@classmethod
def default_from_location(cls):
base, type_ = cls._get_base_contract()
from_location, _ = ContractFactory._get_mirror_locations(base, type_)
return getattr(from_location, 'id', None)
@classmethod
def default_to_location(cls):
base, type_ = cls._get_base_contract()
_, to_location = ContractFactory._get_mirror_locations(base, type_)
return getattr(to_location, 'id', None)
@fields.depends('del_period')
def on_change_del_period(self):
if self.del_period:
self.from_del = self.del_period.beg_date
self.to_del = self.del_period.end_date