refactor models
This commit is contained in:
parent
cf86676e08
commit
16229bd9cd
|
@ -22,13 +22,11 @@ def register():
|
||||||
contract.AgronomicsContractLine,
|
contract.AgronomicsContractLine,
|
||||||
maquila.Configuration,
|
maquila.Configuration,
|
||||||
maquila.ConfigurationSequence,
|
maquila.ConfigurationSequence,
|
||||||
maquila.Maquila,
|
|
||||||
maquila.MaquilaMaquilaContract,
|
|
||||||
maquila.MaquilaProductYearContract,
|
|
||||||
maquila.Contract,
|
maquila.Contract,
|
||||||
maquila.ContractCrop,
|
maquila.ContractCrop,
|
||||||
maquila.ContractProductPercentage,
|
maquila.ContractProductPercentage,
|
||||||
maquila.ProductYear,
|
maquila.ProductYear,
|
||||||
|
maquila.Maquila,
|
||||||
party.Party,
|
party.Party,
|
||||||
plot.Enclosure,
|
plot.Enclosure,
|
||||||
plot.Crop,
|
plot.Crop,
|
||||||
|
|
321
maquila.py
321
maquila.py
|
@ -1,6 +1,6 @@
|
||||||
from trytond.model import (Workflow, Model, ModelSingleton, ModelView, ModelSQL,
|
from trytond.model import (Workflow, ModelSingleton, ModelView, ModelSQL,
|
||||||
fields, sequence_ordered)
|
fields, sequence_ordered)
|
||||||
from trytond.pyson import Id, If, Eval, Bool, PYSONEncoder
|
from trytond.pyson import Id, If, Eval, Bool
|
||||||
from trytond.pool import Pool
|
from trytond.pool import Pool
|
||||||
from trytond.transaction import Transaction
|
from trytond.transaction import Transaction
|
||||||
from trytond.modules.company.model import (
|
from trytond.modules.company.model import (
|
||||||
|
@ -60,72 +60,10 @@ class ConfigurationSequence(ModelSQL, CompanyValueMixin):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class Maquila(ModelSQL, ModelView):
|
|
||||||
"Maquila"
|
|
||||||
__name__ = 'agronomics.maquila'
|
|
||||||
company = fields.Many2One(
|
|
||||||
'company.company', "Company", required=True, select=True, readonly=True)
|
|
||||||
contracts = fields.Many2Many(
|
|
||||||
'agronomics.maquila-agronomics.maquila.contract',
|
|
||||||
'maquila', 'contract', "Contracts", required=True, readonly=True)
|
|
||||||
crop = fields.Many2One('agronomics.crop', "Crop", required=True, readonly=True)
|
|
||||||
party = fields.Many2One('party.party', "Party", required=True, readonly=True,
|
|
||||||
context={
|
|
||||||
'company': Eval('company', -1),
|
|
||||||
},
|
|
||||||
depends=['company'])
|
|
||||||
quantity = fields.Float("Quantity", digits=(16, Eval('unit_digits', 2)),
|
|
||||||
required=True, readonly=True, depends=['unit_digits'])
|
|
||||||
product = fields.Many2One('product.product', "Product", required=True,
|
|
||||||
readonly=True,
|
|
||||||
context={
|
|
||||||
'company': Eval('company', -1),
|
|
||||||
},
|
|
||||||
depends=['company'])
|
|
||||||
unit = fields.Many2One('product.uom', "Unit", required=True, readonly=True,
|
|
||||||
ondelete='RESTRICT', domain=[
|
|
||||||
If(Bool(Eval('product_uom_category')),
|
|
||||||
('category', '=', Eval('product_uom_category')),
|
|
||||||
('category', '!=', -1)),
|
|
||||||
],
|
|
||||||
depends=['product_uom_category'])
|
|
||||||
unit_digits = fields.Function(fields.Integer("Unit Digits"),
|
|
||||||
'on_change_with_unit_digits')
|
|
||||||
product_uom_category = fields.Function(
|
|
||||||
fields.Many2One('product.uom.category', "Product Uom Category"),
|
|
||||||
'on_change_with_product_uom_category')
|
|
||||||
weighings = fields.One2Many('agronomics.weighing', 'maquila',
|
|
||||||
"Weighings", readonly=True)
|
|
||||||
product_year = fields.Many2One('agronomics.maquila.product_year',
|
|
||||||
"Product Year", readonly=True)
|
|
||||||
table = fields.Boolean("Table", readonly=True)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def default_company():
|
|
||||||
return Transaction().context.get('company')
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def __setup__(cls):
|
|
||||||
super(Maquila, cls).__setup__()
|
|
||||||
cls._order = [
|
|
||||||
('id', 'DESC'),
|
|
||||||
]
|
|
||||||
|
|
||||||
@fields.depends('product')
|
|
||||||
def on_change_with_product_uom_category(self, name=None):
|
|
||||||
if self.product:
|
|
||||||
return self.product.default_uom_category.id
|
|
||||||
|
|
||||||
@fields.depends('unit')
|
|
||||||
def on_change_with_unit_digits(self, name=None):
|
|
||||||
if self.unit:
|
|
||||||
return self.unit.digits
|
|
||||||
return 2
|
|
||||||
|
|
||||||
|
|
||||||
class Contract(sequence_ordered(), Workflow, ModelSQL, ModelView):
|
class Contract(sequence_ordered(), Workflow, ModelSQL, ModelView):
|
||||||
"Maquila Contract"
|
"Maquila Contract"
|
||||||
__name__ = 'agronomics.maquila.contract'
|
__name__ = 'agronomics.maquila.contract'
|
||||||
|
_rec_name = 'number'
|
||||||
company = fields.Many2One(
|
company = fields.Many2One(
|
||||||
'company.company', "Company", required=True, select=True,
|
'company.company', "Company", required=True, select=True,
|
||||||
states={
|
states={
|
||||||
|
@ -192,12 +130,6 @@ class Contract(sequence_ordered(), Workflow, ModelSQL, ModelView):
|
||||||
'required': Eval('state') == 'active',
|
'required': Eval('state') == 'active',
|
||||||
},
|
},
|
||||||
depends=['state'])
|
depends=['state'])
|
||||||
product_years = fields.Many2Many(
|
|
||||||
'agronomics.maquila.product_year-agronomics.maquila.contract',
|
|
||||||
'contract', 'product_year', "Product Years", readonly=True)
|
|
||||||
maquilas = fields.Many2Many(
|
|
||||||
'agronomics.maquila-agronomics.maquila.contract',
|
|
||||||
'contract', 'maquila', "Maquilas", readonly=True)
|
|
||||||
table = fields.Boolean("Table",
|
table = fields.Boolean("Table",
|
||||||
states={
|
states={
|
||||||
'readonly': Eval('state') != 'draft',
|
'readonly': Eval('state') != 'draft',
|
||||||
|
@ -251,6 +183,29 @@ class Contract(sequence_ordered(), Workflow, ModelSQL, ModelView):
|
||||||
def default_company():
|
def default_company():
|
||||||
return Transaction().context.get('company')
|
return Transaction().context.get('company')
|
||||||
|
|
||||||
|
def get_rec_name(self, name):
|
||||||
|
items = []
|
||||||
|
if self.number:
|
||||||
|
items.append(self.number)
|
||||||
|
if self.reference:
|
||||||
|
items.append('[%s]' % self.reference)
|
||||||
|
if not items:
|
||||||
|
items.append('(%s)' % self.id)
|
||||||
|
return ' '.join(items)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def search_rec_name(cls, name, clause):
|
||||||
|
_, operator, value = clause
|
||||||
|
if operator.startswith('!') or operator.startswith('not '):
|
||||||
|
bool_op = 'AND'
|
||||||
|
else:
|
||||||
|
bool_op = 'OR'
|
||||||
|
domain = [bool_op,
|
||||||
|
('number', operator, value),
|
||||||
|
('reference', operator, value),
|
||||||
|
]
|
||||||
|
return domain
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def copy(cls, contracts, default=None):
|
def copy(cls, contracts, default=None):
|
||||||
if default is None:
|
if default is None:
|
||||||
|
@ -335,35 +290,39 @@ class Contract(sequence_ordered(), Workflow, ModelSQL, ModelView):
|
||||||
def create_contract_product_year(self):
|
def create_contract_product_year(self):
|
||||||
MaquilaProductYear = Pool().get('agronomics.maquila.product_year')
|
MaquilaProductYear = Pool().get('agronomics.maquila.product_year')
|
||||||
|
|
||||||
crops = [product_crop.crop for product_crop in self.product_crops]
|
crops = set()
|
||||||
|
products = set()
|
||||||
|
for crop in self.product_crops:
|
||||||
|
crops.add(crop.crop)
|
||||||
|
for ppercentatge in self.product_percentages:
|
||||||
|
products.add(ppercentatge.product)
|
||||||
|
|
||||||
records = MaquilaProductYear.search([
|
records = MaquilaProductYear.search([
|
||||||
('party', '=', self.party),
|
('party', '=', self.party),
|
||||||
('crop', 'in', crops),
|
('crop', 'in', crops),
|
||||||
('product', '=', self.product),
|
('product', 'in', products),
|
||||||
# TODO quantity ? quantity = crop.quantity * ppercentatge.percentatge
|
|
||||||
])
|
])
|
||||||
product_years = dict(((x.party, x.crop, x.product), x) for x in records)
|
product_years = dict(((x.party, x.crop, x.product), x) for x in records)
|
||||||
|
|
||||||
new_product_years = []
|
new_product_years = []
|
||||||
for crop in self.product_crops:
|
for crop in self.product_crops:
|
||||||
key = (self.party, crop.crop, self.product)
|
for ppercentatge in self.product_percentages:
|
||||||
if key in product_years:
|
key = (self.party, crop.crop, ppercentatge.product)
|
||||||
product_year = product_years.get(key)
|
if key in product_years:
|
||||||
product_year.contracts += (self,)
|
product_year = product_years.get(key)
|
||||||
product_year.save()
|
crop.product_year = product_year
|
||||||
new_product_years.append(product_year)
|
crop.save()
|
||||||
else:
|
new_product_years.append(product_year)
|
||||||
for ppercentatge in self.product_percentages:
|
else:
|
||||||
product_year = MaquilaProductYear()
|
product_year = MaquilaProductYear()
|
||||||
product_year.company = self.company
|
product_year.company = self.company
|
||||||
product_year.contracts = [self]
|
|
||||||
product_year.party = self.party
|
product_year.party = self.party
|
||||||
product_year.crop = crop.crop
|
product_year.crop = crop.crop
|
||||||
product_year.product = ppercentatge.product
|
product_year.product = ppercentatge.product
|
||||||
product_year.quantity = crop.quantity * ppercentatge.percentatge
|
|
||||||
product_year.unit = ppercentatge.product.default_uom
|
product_year.unit = ppercentatge.product.default_uom
|
||||||
product_year.contracts = [self]
|
|
||||||
product_year.save()
|
product_year.save()
|
||||||
|
crop.product_year = product_year
|
||||||
|
crop.save()
|
||||||
new_product_years.append(product_year)
|
new_product_years.append(product_year)
|
||||||
return new_product_years
|
return new_product_years
|
||||||
|
|
||||||
|
@ -373,37 +332,42 @@ class Contract(sequence_ordered(), Workflow, ModelSQL, ModelView):
|
||||||
default_values = Maquila.default_get(Maquila._fields.keys(),
|
default_values = Maquila.default_get(Maquila._fields.keys(),
|
||||||
with_rec_name=False)
|
with_rec_name=False)
|
||||||
|
|
||||||
crops = [product_crop.crop for product_crop in self.product_crops]
|
crops = set()
|
||||||
|
products = set()
|
||||||
|
for crop in self.product_crops:
|
||||||
|
crops.add(crop.crop)
|
||||||
|
for ppercentatge in self.product_percentages:
|
||||||
|
products.add(ppercentatge.product)
|
||||||
|
|
||||||
records = Maquila.search([
|
records = Maquila.search([
|
||||||
('party', '=', self.party),
|
('party', '=', self.party),
|
||||||
('crop', 'in', crops),
|
('crop', 'in', crops),
|
||||||
('product', '=', self.product),
|
('product', 'in', products),
|
||||||
# TODO quantity ? quantity = crop.quantity * ppercentatge.percentatge
|
|
||||||
])
|
])
|
||||||
maquilas = dict(((x.party, x.crop, x.table), x) for x in records)
|
maquilas = dict(((x.party, x.product, x.crop, x.table), x) for x in records)
|
||||||
|
|
||||||
new_maquilas = []
|
new_maquilas = []
|
||||||
for product_year in self.product_years:
|
for crop in self.product_crops:
|
||||||
key = (self.party, product_year.crop, self.table)
|
for ppercentatge in self.product_percentages:
|
||||||
if key in maquilas:
|
key = (self.party, ppercentatge.product, crop.crop, self.table)
|
||||||
maquila = maquilas.get(key)
|
if key in maquilas:
|
||||||
maquila.contracts += (self,)
|
maquila = maquilas.get(key)
|
||||||
maquila.save()
|
crop.maquila = maquila
|
||||||
new_maquilas.append(maquila)
|
crop.save()
|
||||||
else:
|
new_maquilas.append(maquila)
|
||||||
maquila = Maquila(**default_values)
|
else:
|
||||||
maquila.company = self.company
|
maquila = Maquila(**default_values)
|
||||||
maquila.contracts = [self]
|
maquila.company = self.company
|
||||||
maquila.party = self.party
|
maquila.party = self.party
|
||||||
maquila.crop = product_year.crop
|
maquila.crop = crop.crop
|
||||||
maquila.party = self.party
|
maquila.party = self.party
|
||||||
maquila.product = product_year.product
|
maquila.product = ppercentatge.product
|
||||||
maquila.quantity = product_year.quantity
|
maquila.unit = ppercentatge.product.default_uom
|
||||||
maquila.unit = product_year.product.default_uom
|
maquila.table = self.table
|
||||||
maquila.product_year = product_year
|
maquila.save()
|
||||||
maquila.table = self.table
|
crop.maquila = maquila
|
||||||
maquila.save()
|
crop.save()
|
||||||
new_maquilas.append(maquila)
|
new_maquilas.append(maquila)
|
||||||
return new_maquilas
|
return new_maquilas
|
||||||
|
|
||||||
|
|
||||||
|
@ -418,6 +382,9 @@ class ContractCrop(ModelSQL, ModelView):
|
||||||
depends=['currency_digits'], required=True)
|
depends=['currency_digits'], required=True)
|
||||||
currency_digits = fields.Function(fields.Integer('Currency Digits'),
|
currency_digits = fields.Function(fields.Integer('Currency Digits'),
|
||||||
'on_change_with_currency_digits')
|
'on_change_with_currency_digits')
|
||||||
|
product_year = fields.Many2One('agronomics.maquila.product_year',
|
||||||
|
"Product Year", readonly=True)
|
||||||
|
maquila = fields.Many2One('agronomics.maquila', "Maquila", readonly=True)
|
||||||
|
|
||||||
def on_change_with_currency_digits(self, name=None):
|
def on_change_with_currency_digits(self, name=None):
|
||||||
Company = Pool().get('company.company')
|
Company = Pool().get('company.company')
|
||||||
|
@ -442,9 +409,6 @@ class ProductYear(ModelSQL, ModelView):
|
||||||
__name__ = 'agronomics.maquila.product_year'
|
__name__ = 'agronomics.maquila.product_year'
|
||||||
company = fields.Many2One(
|
company = fields.Many2One(
|
||||||
'company.company', "Company", required=True, select=True, readonly=True)
|
'company.company', "Company", required=True, select=True, readonly=True)
|
||||||
contracts = fields.Many2Many(
|
|
||||||
'agronomics.maquila.product_year-agronomics.maquila.contract',
|
|
||||||
'product_year', 'contract', "Contracts", required=True, readonly=True)
|
|
||||||
party = fields.Many2One('party.party', "Party", required=True, readonly=True,
|
party = fields.Many2One('party.party', "Party", required=True, readonly=True,
|
||||||
context={
|
context={
|
||||||
'company': Eval('company', -1),
|
'company': Eval('company', -1),
|
||||||
|
@ -454,9 +418,9 @@ class ProductYear(ModelSQL, ModelView):
|
||||||
readonly=True)
|
readonly=True)
|
||||||
product = fields.Many2One('product.product', "Product", required=True,
|
product = fields.Many2One('product.product', "Product", required=True,
|
||||||
readonly=True)
|
readonly=True)
|
||||||
quantity = fields.Float('Quantity', required=True, readonly=True,
|
quantity = fields.Function(fields.Float("Quantity",
|
||||||
digits=(16, Eval('unit_digits', 2)),
|
digits=(16, Eval('unit_digits', 2)),
|
||||||
depends=['unit_digits'])
|
depends=['unit_digits']), 'get_quantity')
|
||||||
unit = fields.Many2One('product.uom', "Unit", required=True, readonly=True,
|
unit = fields.Many2One('product.uom', "Unit", required=True, readonly=True,
|
||||||
ondelete='RESTRICT', domain=[
|
ondelete='RESTRICT', domain=[
|
||||||
If(Bool(Eval('product_uom_category')),
|
If(Bool(Eval('product_uom_category')),
|
||||||
|
@ -469,6 +433,10 @@ class ProductYear(ModelSQL, ModelView):
|
||||||
product_uom_category = fields.Function(
|
product_uom_category = fields.Function(
|
||||||
fields.Many2One('product.uom.category', "Product Uom Category"),
|
fields.Many2One('product.uom.category', "Product Uom Category"),
|
||||||
'on_change_with_product_uom_category')
|
'on_change_with_product_uom_category')
|
||||||
|
contract_crops = fields.One2Many('agronomics.maquila.contract.crop',
|
||||||
|
'product_year', "Crops", readonly=True)
|
||||||
|
contracts = fields.Function(fields.One2Many('agronomics.maquila.contract',
|
||||||
|
None, "Contracts"), 'get_contracts', searcher='search_contracts')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __setup__(cls):
|
def __setup__(cls):
|
||||||
|
@ -498,22 +466,115 @@ class ProductYear(ModelSQL, ModelView):
|
||||||
self.unit = self.product.default_uom
|
self.unit = self.product.default_uom
|
||||||
self.unit_digits = self.product.default_uom.digits
|
self.unit_digits = self.product.default_uom.digits
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_quantity(cls, product_years, name):
|
||||||
|
res = dict((x.id, 0) for x in product_years)
|
||||||
|
for product_year in product_years:
|
||||||
|
_sum = 0
|
||||||
|
for crop in product_year.contract_crops:
|
||||||
|
for ppercentatge in crop.contract.product_percentages:
|
||||||
|
if ppercentatge.product == product_year.product:
|
||||||
|
_sum += crop.quantity * ppercentatge.percentatge
|
||||||
|
res[product_year.id] = _sum
|
||||||
|
return res
|
||||||
|
|
||||||
class MaquilaProductYearContract(ModelSQL):
|
@classmethod
|
||||||
'Maquila Product Year - Maquila Contract'
|
def get_contracts(cls, product_years, name):
|
||||||
__name__ = 'agronomics.maquila.product_year-agronomics.maquila.contract'
|
res = dict((x.id, None) for x in product_years)
|
||||||
_table = 'agronomics_maquila_product_year_contract_rel'
|
for product_year in product_years:
|
||||||
|
contracts = [crop.contract.id for crop in product_year.contract_crops]
|
||||||
|
res[product_year.id] = contracts
|
||||||
|
return res
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def search_contracts(cls, name, clause):
|
||||||
|
return [('contract_crops.contract',) + tuple(clause[1:])]
|
||||||
|
|
||||||
|
|
||||||
|
class Maquila(ModelSQL, ModelView):
|
||||||
|
"Maquila"
|
||||||
|
__name__ = 'agronomics.maquila'
|
||||||
|
company = fields.Many2One(
|
||||||
|
'company.company', "Company", required=True, select=True, readonly=True)
|
||||||
|
crop = fields.Many2One('agronomics.crop', "Crop", required=True, readonly=True)
|
||||||
|
party = fields.Many2One('party.party', "Party", required=True, readonly=True,
|
||||||
|
context={
|
||||||
|
'company': Eval('company', -1),
|
||||||
|
},
|
||||||
|
depends=['company'])
|
||||||
|
quantity = fields.Function(fields.Float("Quantity",
|
||||||
|
digits=(16, Eval('unit_digits', 2)),
|
||||||
|
depends=['unit_digits']), 'get_quantity')
|
||||||
|
product = fields.Many2One('product.product', "Product", required=True,
|
||||||
|
readonly=True,
|
||||||
|
context={
|
||||||
|
'company': Eval('company', -1),
|
||||||
|
},
|
||||||
|
depends=['company'])
|
||||||
|
unit = fields.Many2One('product.uom', "Unit", required=True, readonly=True,
|
||||||
|
ondelete='RESTRICT', domain=[
|
||||||
|
If(Bool(Eval('product_uom_category')),
|
||||||
|
('category', '=', Eval('product_uom_category')),
|
||||||
|
('category', '!=', -1)),
|
||||||
|
],
|
||||||
|
depends=['product_uom_category'])
|
||||||
|
unit_digits = fields.Function(fields.Integer("Unit Digits"),
|
||||||
|
'on_change_with_unit_digits')
|
||||||
|
product_uom_category = fields.Function(
|
||||||
|
fields.Many2One('product.uom.category', "Product Uom Category"),
|
||||||
|
'on_change_with_product_uom_category')
|
||||||
|
weighings = fields.One2Many('agronomics.weighing', 'maquila',
|
||||||
|
"Weighings", readonly=True)
|
||||||
product_year = fields.Many2One('agronomics.maquila.product_year',
|
product_year = fields.Many2One('agronomics.maquila.product_year',
|
||||||
"Product Year", ondelete='CASCADE', required=True, select=True)
|
"Product Year", readonly=True)
|
||||||
contract = fields.Many2One('agronomics.maquila.contract', "Contract",
|
table = fields.Boolean("Table", readonly=True)
|
||||||
ondelete='CASCADE', required=True, select=True)
|
contract_crops = fields.One2Many('agronomics.maquila.contract.crop', 'maquila',
|
||||||
|
"Crops", readonly=True)
|
||||||
|
contracts = fields.Function(fields.One2Many('agronomics.maquila.contract',
|
||||||
|
None, "Contracts"), 'get_contracts', searcher='search_contracts')
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def default_company():
|
||||||
|
return Transaction().context.get('company')
|
||||||
|
|
||||||
class MaquilaMaquilaContract(ModelSQL):
|
@classmethod
|
||||||
'Maquila - Maquila Contract'
|
def __setup__(cls):
|
||||||
__name__ = 'agronomics.maquila-agronomics.maquila.contract'
|
super(Maquila, cls).__setup__()
|
||||||
_table = 'agronomics_maquila_contract_rel'
|
cls._order = [
|
||||||
maquila = fields.Many2One('agronomics.maquila',
|
('id', 'DESC'),
|
||||||
"Maquila", ondelete='CASCADE', required=True, select=True)
|
]
|
||||||
contract = fields.Many2One('agronomics.maquila.contract', "Contract",
|
|
||||||
ondelete='CASCADE', required=True, select=True)
|
@fields.depends('product')
|
||||||
|
def on_change_with_product_uom_category(self, name=None):
|
||||||
|
if self.product:
|
||||||
|
return self.product.default_uom_category.id
|
||||||
|
|
||||||
|
@fields.depends('unit')
|
||||||
|
def on_change_with_unit_digits(self, name=None):
|
||||||
|
if self.unit:
|
||||||
|
return self.unit.digits
|
||||||
|
return 2
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_quantity(cls, product_years, name):
|
||||||
|
res = dict((x.id, 0) for x in product_years)
|
||||||
|
for product_year in product_years:
|
||||||
|
_sum = 0
|
||||||
|
for crop in product_year.contract_crops:
|
||||||
|
for ppercentatge in crop.contract.product_percentages:
|
||||||
|
if ppercentatge.product == product_year.product:
|
||||||
|
_sum += crop.quantity * ppercentatge.percentatge
|
||||||
|
res[product_year.id] = _sum
|
||||||
|
return res
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_contracts(cls, product_years, name):
|
||||||
|
res = dict((x.id, None) for x in product_years)
|
||||||
|
for product_year in product_years:
|
||||||
|
contracts = [crop.contract.id for crop in product_year.contract_crops]
|
||||||
|
res[product_year.id] = contracts
|
||||||
|
return res
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def search_contracts(cls, name, clause):
|
||||||
|
return [('contract_crops.contract',) + tuple(clause[1:])]
|
||||||
|
|
26
maquila.xml
26
maquila.xml
|
@ -191,6 +191,32 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
<field name="rule_group" ref="rule_group_maquila_contract_companies"/>
|
<field name="rule_group" ref="rule_group_maquila_contract_companies"/>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.action.act_window" id="act_maquila_contract_maquila_product_year_form">
|
||||||
|
<field name="name">Product Years</field>
|
||||||
|
<field name="res_model">agronomics.maquila.product_year</field>
|
||||||
|
<field name="domain"
|
||||||
|
eval="[If(Eval('active_ids', []) == [Eval('active_id')], ('contract_crops.contract', '=', Eval('active_id')), ('contract_crops.contract', 'in', Eval('active_ids')))]"
|
||||||
|
pyson="1"/>
|
||||||
|
</record>
|
||||||
|
<record model="ir.action.keyword" id="act_open_maquila_contract_maquila_product_year_keyword1">
|
||||||
|
<field name="keyword">form_relate</field>
|
||||||
|
<field name="model">agronomics.maquila.contract,-1</field>
|
||||||
|
<field name="action" ref="act_maquila_contract_maquila_product_year_form"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.action.act_window" id="act_maquila_contract_maquila_form">
|
||||||
|
<field name="name">Maquilas</field>
|
||||||
|
<field name="res_model">agronomics.maquila</field>
|
||||||
|
<field name="domain"
|
||||||
|
eval="[If(Eval('active_ids', []) == [Eval('active_id')], ('contract_crops.contract', '=', Eval('active_id')), ('contract_crops.contract', 'in', Eval('active_ids')))]"
|
||||||
|
pyson="1"/>
|
||||||
|
</record>
|
||||||
|
<record model="ir.action.keyword" id="act_open_maquila_contract_maquila_keyword1">
|
||||||
|
<field name="keyword">form_relate</field>
|
||||||
|
<field name="model">agronomics.maquila.contract,-1</field>
|
||||||
|
<field name="action" ref="act_maquila_contract_maquila_form"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
<!-- agronomics.maquila.contract.crop -->
|
<!-- agronomics.maquila.contract.crop -->
|
||||||
<record model="ir.ui.view" id="maquila_contract_crop_view_form">
|
<record model="ir.ui.view" id="maquila_contract_crop_view_form">
|
||||||
<field name="model">agronomics.maquila.contract.crop</field>
|
<field name="model">agronomics.maquila.contract.crop</field>
|
||||||
|
|
|
@ -8,4 +8,6 @@
|
||||||
<field name="quantity"/>
|
<field name="quantity"/>
|
||||||
<label name="penality"/>
|
<label name="penality"/>
|
||||||
<field name="penality"/>
|
<field name="penality"/>
|
||||||
|
<label name="maquila"/>
|
||||||
|
<field name="maquila"/>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -25,12 +25,6 @@
|
||||||
<page name="product_percentages">
|
<page name="product_percentages">
|
||||||
<field name="product_percentages"/>
|
<field name="product_percentages"/>
|
||||||
</page>
|
</page>
|
||||||
<page name="product_years">
|
|
||||||
<field name="product_years"/>
|
|
||||||
</page>
|
|
||||||
<page name="maquilas">
|
|
||||||
<field name="maquilas"/>
|
|
||||||
</page>
|
|
||||||
</notebook>
|
</notebook>
|
||||||
<group col="6" colspan="6" id="server_buttons">
|
<group col="6" colspan="6" id="server_buttons">
|
||||||
<label name="state"/>
|
<label name="state"/>
|
||||||
|
|
|
@ -7,6 +7,4 @@
|
||||||
<field name="table"/>
|
<field name="table"/>
|
||||||
<field name="state"/>
|
<field name="state"/>
|
||||||
<field name="company"/>
|
<field name="company"/>
|
||||||
<field name="product_years" tree_invisible="1"/>
|
|
||||||
<field name="maquilas" tree_invisible="1"/>
|
|
||||||
</tree>
|
</tree>
|
||||||
|
|
|
@ -15,5 +15,6 @@
|
||||||
<label name="company"/>
|
<label name="company"/>
|
||||||
<field name="company"/>
|
<field name="company"/>
|
||||||
<newline/>
|
<newline/>
|
||||||
<field name="contracts" colspan="4"/>
|
<field name="contract_crops" colspan="6"/>
|
||||||
|
<field name="contracts" colspan="6"/>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -5,6 +5,6 @@
|
||||||
<field name="table"/>
|
<field name="table"/>
|
||||||
<field name="product"/>
|
<field name="product"/>
|
||||||
<field name="unit"/>
|
<field name="unit"/>
|
||||||
<field name="quantity"/>
|
|
||||||
<field name="company"/>
|
<field name="company"/>
|
||||||
|
<field name="contracts" tree_invisible="1"/>
|
||||||
</tree>
|
</tree>
|
||||||
|
|
|
@ -11,5 +11,6 @@
|
||||||
<label name="unit"/>
|
<label name="unit"/>
|
||||||
<field name="unit"/>
|
<field name="unit"/>
|
||||||
<newline/>
|
<newline/>
|
||||||
<field name="contracts" colspan="4"/>
|
<field name="contract_crops" colspan="6"/>
|
||||||
|
<field name="contracts" colspan="6"/>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue