mirror of
https://github.com/NaN-tic/trytond-agronomics.git
synced 2023-12-14 05:33:01 +01:00
create maquila and product years same values and different contract
This commit is contained in:
parent
08e4f50675
commit
38373215fc
12 changed files with 317 additions and 206 deletions
|
@ -23,10 +23,12 @@ def register():
|
|||
maquila.Configuration,
|
||||
maquila.ConfigurationSequence,
|
||||
maquila.Maquila,
|
||||
maquila.MaquilaMaquilaContract,
|
||||
maquila.MaquilaProductYearContract,
|
||||
maquila.Contract,
|
||||
maquila.ContractCrop,
|
||||
maquila.ContractProductPercentage,
|
||||
maquila.ContractProductYear,
|
||||
maquila.ProductYear,
|
||||
party.Party,
|
||||
plot.Enclosure,
|
||||
plot.Crop,
|
||||
|
|
199
maquila.py
199
maquila.py
|
@ -65,8 +65,9 @@ class Maquila(ModelSQL, ModelView):
|
|||
__name__ = 'agronomics.maquila'
|
||||
company = fields.Many2One(
|
||||
'company.company', "Company", required=True, select=True, readonly=True)
|
||||
contract = fields.Many2One('agronomics.maquila.contract', "Contract",
|
||||
ondelete='CASCADE', select=True, required=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={
|
||||
|
@ -93,11 +94,23 @@ class Maquila(ModelSQL, ModelView):
|
|||
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:
|
||||
|
@ -168,20 +181,22 @@ class Contract(sequence_ordered(), Workflow, ModelSQL, ModelView):
|
|||
'contract', "Product Crops",
|
||||
states={
|
||||
'readonly': Eval('state') != 'draft',
|
||||
'required': Eval('state') == 'active',
|
||||
},
|
||||
depends=['state'])
|
||||
product_percentages = fields.One2Many('agronomics.maquila.contract.product_percentage',
|
||||
'contract', "Product Percentatges",
|
||||
states={
|
||||
'readonly': Eval('state') != 'draft',
|
||||
'required': Eval('state') == 'active',
|
||||
},
|
||||
depends=['state'])
|
||||
product_years = fields.One2Many('agronomics.maquila.contract.product_year',
|
||||
'contract', "Product Years", readonly=True,
|
||||
states={
|
||||
'readonly': Eval('state') != 'draft',
|
||||
},
|
||||
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",
|
||||
states={
|
||||
'readonly': Eval('state') != 'draft',
|
||||
|
@ -197,17 +212,19 @@ class Contract(sequence_ordered(), Workflow, ModelSQL, ModelView):
|
|||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Contract, cls).__setup__()
|
||||
cls._order = [
|
||||
('number', 'DESC NULLS FIRST'),
|
||||
('id', 'DESC'),
|
||||
]
|
||||
cls._transitions |= set((
|
||||
('draft', 'active'),
|
||||
('active', 'cancelled'),
|
||||
('draft', 'cancelled'),
|
||||
('active', 'done'),
|
||||
('active', 'draft'),
|
||||
('cancelled', 'draft'),
|
||||
|
||||
))
|
||||
cls._buttons.update({
|
||||
'draft': {
|
||||
'invisible': ~Eval('state').in_(['cancelled', 'active']),
|
||||
'invisible': Eval('state') != 'cancelled',
|
||||
'icon': If(Eval('state') == 'cancelled', 'tryton-undo',
|
||||
'tryton-back'),
|
||||
},
|
||||
|
@ -216,7 +233,7 @@ class Contract(sequence_ordered(), Workflow, ModelSQL, ModelView):
|
|||
'icon': 'tryton-forward',
|
||||
},
|
||||
'cancel': {
|
||||
'invisible': Eval('state') != 'active',
|
||||
'invisible': Eval('state') != 'draft',
|
||||
'icon': 'tryton-cancel',
|
||||
},
|
||||
'done': {
|
||||
|
@ -240,6 +257,8 @@ class Contract(sequence_ordered(), Workflow, ModelSQL, ModelView):
|
|||
else:
|
||||
default = default.copy()
|
||||
default.setdefault('number', None)
|
||||
default.setdefault('product_years', None)
|
||||
default.setdefault('maquilas', None)
|
||||
return super(Contract, cls).copy(contracts, default=default)
|
||||
|
||||
@fields.depends('product')
|
||||
|
@ -273,9 +292,7 @@ class Contract(sequence_ordered(), Workflow, ModelSQL, ModelView):
|
|||
@ModelView.button
|
||||
@Workflow.transition('draft')
|
||||
def draft(cls, contracts):
|
||||
for contract in contracts:
|
||||
contract.delete_contract_product_year()
|
||||
contract.delete_maquila()
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
|
@ -284,8 +301,6 @@ class Contract(sequence_ordered(), Workflow, ModelSQL, ModelView):
|
|||
for contract in contracts:
|
||||
contract.check_quantity()
|
||||
contract.create_contract_product_year()
|
||||
# TODO si active -> create_contract_product_year
|
||||
# also create_maquila from product_years that create_contract_product_year ?
|
||||
contract.create_maquila()
|
||||
cls.set_number(contracts)
|
||||
|
||||
|
@ -317,28 +332,39 @@ class Contract(sequence_ordered(), Workflow, ModelSQL, ModelView):
|
|||
contract=self.rec_name))
|
||||
|
||||
def create_contract_product_year(self):
|
||||
ContractProductYear = Pool().get('agronomics.maquila.contract.product_year')
|
||||
MaquilaProductYear = Pool().get('agronomics.maquila.product_year')
|
||||
|
||||
product_years = []
|
||||
for crop in self.product_crops:
|
||||
for ppercentatge in self.product_percentages:
|
||||
product_year = ContractProductYear()
|
||||
product_year.contract = self
|
||||
product_year.crop = crop.crop
|
||||
product_year.product = contract.product
|
||||
product_year.quantity = crop.quantity * ppercentatge.percentatge
|
||||
product_year.unit = contract.unit
|
||||
product_year.save()
|
||||
product_years.append(product_year)
|
||||
return product_years
|
||||
|
||||
def delete_contract_product_year(self):
|
||||
ContractProductYear = Pool().get('agronomics.maquila.contract.product_year')
|
||||
|
||||
product_years = ContractProductYear.search([
|
||||
('contract', '=', self),
|
||||
crops = [product_crop.crop for product_crop in self.product_crops]
|
||||
records = MaquilaProductYear.search([
|
||||
('party', '=', self.party),
|
||||
('crop', 'in', crops),
|
||||
('product', '=', self.product),
|
||||
# TODO quantity ? quantity = crop.quantity * ppercentatge.percentatge
|
||||
])
|
||||
ContractProductYear.delete(product_years)
|
||||
product_years = dict(((x.party, x.crop, x.product), x) for x in records)
|
||||
|
||||
new_product_years = []
|
||||
for crop in self.product_crops:
|
||||
key = (self.party, crop.crop, self.product)
|
||||
if key in product_years:
|
||||
product_year = product_years.get(key)
|
||||
product_year.contracts += (self,)
|
||||
product_year.save()
|
||||
new_product_years.append(product_year)
|
||||
else:
|
||||
for ppercentatge in self.product_percentages:
|
||||
product_year = MaquilaProductYear()
|
||||
product_year.company = self.company
|
||||
product_year.contracts = [self]
|
||||
product_year.party = self.party
|
||||
product_year.crop = crop.crop
|
||||
product_year.product = self.product
|
||||
product_year.quantity = crop.quantity * ppercentatge.percentatge
|
||||
product_year.unit = self.unit
|
||||
product_year.contracts = [self]
|
||||
product_year.save()
|
||||
new_product_years.append(product_year)
|
||||
return new_product_years
|
||||
|
||||
def create_maquila(self):
|
||||
Maquila = Pool().get('agronomics.maquila')
|
||||
|
@ -346,27 +372,39 @@ class Contract(sequence_ordered(), Workflow, ModelSQL, ModelView):
|
|||
default_values = Maquila.default_get(Maquila._fields.keys(),
|
||||
with_rec_name=False)
|
||||
|
||||
maquilas = []
|
||||
for crop in self.product_years:
|
||||
for ppercentatge in self.product_percentages:
|
||||
maquila = Maquila(**default_values)
|
||||
maquila.contract = self
|
||||
maquila.crop = crop
|
||||
maquila.party = self.party
|
||||
maquila.product = contract.product
|
||||
maquila.quantity = crop.quantity * ppercentatge.percentatge
|
||||
maquila.unit = contract.unit
|
||||
maquila.save()
|
||||
maquilas.append(maquila)
|
||||
return maquilas
|
||||
|
||||
def delete_maquila(self):
|
||||
Maquila = Pool().get('agronomics.maquila')
|
||||
|
||||
maquilas = Maquila.search([
|
||||
('contract', '=', self),
|
||||
crops = [product_crop.crop for product_crop in self.product_crops]
|
||||
records = Maquila.search([
|
||||
('party', '=', self.party),
|
||||
('crop', 'in', crops),
|
||||
('product', '=', self.product),
|
||||
# TODO quantity ? quantity = crop.quantity * ppercentatge.percentatge
|
||||
])
|
||||
Maquila.delete(maquilas)
|
||||
maquilas = dict(((x.party, x.crop, x.table), x) for x in records)
|
||||
|
||||
new_maquilas = []
|
||||
for product_year in self.product_years:
|
||||
key = (self.party, product_year.crop, self.table)
|
||||
if key in maquilas:
|
||||
maquila = maquilas.get(key)
|
||||
maquila.contracts += (self,)
|
||||
maquila.save()
|
||||
new_maquilas.append(maquila)
|
||||
else:
|
||||
for ppercentatge in self.product_percentages:
|
||||
maquila = Maquila(**default_values)
|
||||
maquila.company = self.company
|
||||
maquila.contracts = [self]
|
||||
maquila.party = self.party
|
||||
maquila.crop = product_year.crop
|
||||
maquila.party = self.party
|
||||
maquila.product = self.product
|
||||
maquila.quantity = self.quantity * ppercentatge.percentatge
|
||||
maquila.unit = self.unit
|
||||
maquila.product_year = product_year
|
||||
maquila.table = self.table
|
||||
maquila.save()
|
||||
new_maquilas.append(maquila)
|
||||
return new_maquilas
|
||||
|
||||
|
||||
class ContractCrop(ModelSQL, ModelView):
|
||||
|
@ -399,11 +437,19 @@ class ContractProductPercentage(ModelSQL, ModelView):
|
|||
percentatge = fields.Float("Percentatge", digits=(16, 4), required=True)
|
||||
|
||||
|
||||
class ContractProductYear(ModelSQL, ModelView):
|
||||
"Maquila Contract Product Year"
|
||||
__name__ = 'agronomics.maquila.contract.product_year'
|
||||
contract = fields.Many2One('agronomics.maquila.contract', "Contract",
|
||||
ondelete='CASCADE', select=True, required=True, readonly=True)
|
||||
class ProductYear(ModelSQL, ModelView):
|
||||
"Maquila Product Year"
|
||||
__name__ = 'agronomics.maquila.product_year'
|
||||
company = fields.Many2One(
|
||||
'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,
|
||||
context={
|
||||
'company': Eval('company', -1),
|
||||
},
|
||||
depends=['company'])
|
||||
crop = fields.Many2One('agronomics.crop', "Crop", required=True,
|
||||
readonly=True)
|
||||
product = fields.Many2One('product.product', "Product", required=True,
|
||||
|
@ -424,6 +470,13 @@ class ContractProductYear(ModelSQL, ModelView):
|
|||
fields.Many2One('product.uom.category', "Product Uom Category"),
|
||||
'on_change_with_product_uom_category')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(ProductYear, cls).__setup__()
|
||||
cls._order = [
|
||||
('id', 'DESC'),
|
||||
]
|
||||
|
||||
@fields.depends('product')
|
||||
def on_change_with_product_uom_category(self, name=None):
|
||||
if self.product:
|
||||
|
@ -444,3 +497,23 @@ class ContractProductYear(ModelSQL, ModelView):
|
|||
if not self.unit or self.unit.category != category:
|
||||
self.unit = self.product.default_uom
|
||||
self.unit_digits = self.product.default_uom.digits
|
||||
|
||||
|
||||
class MaquilaProductYearContract(ModelSQL):
|
||||
'Maquila Product Year - Maquila Contract'
|
||||
__name__ = 'agronomics.maquila.product_year-agronomics.maquila.contract'
|
||||
_table = 'agronomics_maquila_product_year_contract_rel'
|
||||
product_year = fields.Many2One('agronomics.maquila.product_year',
|
||||
"Product Year", ondelete='CASCADE', required=True, select=True)
|
||||
contract = fields.Many2One('agronomics.maquila.contract', "Contract",
|
||||
ondelete='CASCADE', required=True, select=True)
|
||||
|
||||
|
||||
class MaquilaMaquilaContract(ModelSQL):
|
||||
'Maquila - Maquila Contract'
|
||||
__name__ = 'agronomics.maquila-agronomics.maquila.contract'
|
||||
_table = 'agronomics_maquila_contract_rel'
|
||||
maquila = fields.Many2One('agronomics.maquila',
|
||||
"Maquila", ondelete='CASCADE', required=True, select=True)
|
||||
contract = fields.Many2One('agronomics.maquila.contract', "Contract",
|
||||
ondelete='CASCADE', required=True, select=True)
|
||||
|
|
222
maquila.xml
222
maquila.xml
|
@ -65,73 +65,6 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
|
||||
<!-- agronomics.maquila -->
|
||||
<record model="ir.ui.view" id="maquila_view_form">
|
||||
<field name="model">agronomics.maquila</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">maquila_form</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="maquila_view_tree">
|
||||
<field name="model">agronomics.maquila</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="priority" eval="20"/>
|
||||
<field name="name">maquila_list</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.act_window" id="act_maquila_form">
|
||||
<field name="name">Maquila</field>
|
||||
<field name="res_model">agronomics.maquila</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_maquila_tree_view1">
|
||||
<field name="sequence" eval="10"/>
|
||||
<field name="view" ref="maquila_view_tree"/>
|
||||
<field name="act_window" ref="act_maquila_form"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_maquila_tree_view2">
|
||||
<field name="sequence" eval="20"/>
|
||||
<field name="view" ref="maquila_view_form"/>
|
||||
<field name="act_window" ref="act_maquila_form"/>
|
||||
</record>
|
||||
|
||||
<menuitem parent="menu_maquila" sequence="1"
|
||||
action="act_maquila_form" id="menu_maquila_list"/>
|
||||
|
||||
<record model="ir.model.access" id="access_maquila">
|
||||
<field name="model" search="[('model', '=', 'agronomics.maquila')]"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="False"/>
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_delete" eval="False"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_maquila_agronomics">
|
||||
<field name="model" search="[('model', '=', 'agronomics.maquila')]"/>
|
||||
<field name="group" ref="agronomics.group_agronomics"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_maquila_admin">
|
||||
<field name="model" search="[('model', '=', 'agronomics.maquila')]"/>
|
||||
<field name="group" ref="agronomics.group_agronomics_admin"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.rule.group" id="rule_group_maquila_companies">
|
||||
<field name="name">User in companies</field>
|
||||
<field name="model" search="[('model', '=', 'agronomics.maquila')]"/>
|
||||
<field name="global_p" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.rule" id="rule_maquila_companies">
|
||||
<field name="domain"
|
||||
eval="[('company', 'in', Eval('companies', []))]"
|
||||
pyson="1"/>
|
||||
<field name="rule_group" ref="rule_group_maquila_companies"/>
|
||||
</record>
|
||||
|
||||
<!-- agronomics.maquila.contract -->
|
||||
<record model="ir.ui.view" id="maquila_contract_view_form">
|
||||
<field name="model">agronomics.maquila.contract</field>
|
||||
|
@ -314,32 +247,155 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="act_window" ref="act_maquila_contract_product_percentage_form"/>
|
||||
</record>
|
||||
|
||||
<!-- agronomics.maquila.contract.product_year -->
|
||||
<record model="ir.ui.view" id="maquila_contract_product_year_view_form">
|
||||
<field name="model">agronomics.maquila.contract.product_year</field>
|
||||
<!-- agronomics.maquila.product_year -->
|
||||
<record model="ir.ui.view" id="maquila_product_year_view_form">
|
||||
<field name="model">agronomics.maquila.product_year</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">maquila_contract_product_year_form</field>
|
||||
<field name="name">maquila_product_year_form</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="maquila_contract_product_year_view_tree">
|
||||
<field name="model">agronomics.maquila.contract.product_year</field>
|
||||
<record model="ir.ui.view" id="maquila_product_year_view_tree">
|
||||
<field name="model">agronomics.maquila.product_year</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="priority" eval="20"/>
|
||||
<field name="name">maquila_contract_product_year_list</field>
|
||||
<field name="name">maquila_product_year_list</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.act_window" id="act_maquila_contract_product_year_form">
|
||||
<field name="name">Maquila Contract Product Year</field>
|
||||
<field name="res_model">agronomics.maquila.contract.product_year</field>
|
||||
<record model="ir.action.act_window" id="act_maquila_product_year_form">
|
||||
<field name="name">Maquila Product Year</field>
|
||||
<field name="res_model">agronomics.maquila.product_year</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_maquila_contract_product_year_tree_view1">
|
||||
<record model="ir.action.act_window.view" id="act_maquila_product_year_tree_view1">
|
||||
<field name="sequence" eval="10"/>
|
||||
<field name="view" ref="maquila_contract_product_year_view_tree"/>
|
||||
<field name="act_window" ref="act_maquila_contract_product_year_form"/>
|
||||
<field name="view" ref="maquila_product_year_view_tree"/>
|
||||
<field name="act_window" ref="act_maquila_product_year_form"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_maquila_contract_product_year_tree_view2">
|
||||
<record model="ir.action.act_window.view" id="act_maquila_product_year_tree_view2">
|
||||
<field name="sequence" eval="20"/>
|
||||
<field name="view" ref="maquila_contract_product_year_view_form"/>
|
||||
<field name="act_window" ref="act_maquila_contract_product_year_form"/>
|
||||
<field name="view" ref="maquila_product_year_view_form"/>
|
||||
<field name="act_window" ref="act_maquila_product_year_form"/>
|
||||
</record>
|
||||
|
||||
<menuitem parent="menu_maquila" sequence="20"
|
||||
action="act_maquila_product_year_form" id="menu_maquila_product_year_list"/>
|
||||
|
||||
<record model="ir.model.access" id="access_maquila_product_year">
|
||||
<field name="model" search="[('model', '=', 'agronomics.maquila.product_year')]"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="False"/>
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_delete" eval="False"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_maquila_product_year_agronomics">
|
||||
<field name="model" search="[('model', '=', 'agronomics.maquila.product_year')]"/>
|
||||
<field name="group" ref="agronomics.group_agronomics"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_delete" eval="False"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_maquila_product_year_admin">
|
||||
<field name="model" search="[('model', '=', 'agronomics.maquila.product_year')]"/>
|
||||
<field name="group" ref="agronomics.group_agronomics_admin"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.rule.group" id="rule_group_maquila_product_year_companies">
|
||||
<field name="name">User in companies</field>
|
||||
<field name="model" search="[('model', '=', 'agronomics.maquila.product_year')]"/>
|
||||
<field name="global_p" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.rule" id="rule_maquila_product_year_companies">
|
||||
<field name="domain"
|
||||
eval="[('company', 'in', Eval('companies', []))]"
|
||||
pyson="1"/>
|
||||
<field name="rule_group" ref="rule_group_maquila_product_year_companies"/>
|
||||
</record>
|
||||
|
||||
<!-- agronomics.maquila -->
|
||||
<record model="ir.ui.view" id="maquila_view_form">
|
||||
<field name="model">agronomics.maquila</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">maquila_form</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="maquila_view_tree">
|
||||
<field name="model">agronomics.maquila</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="priority" eval="20"/>
|
||||
<field name="name">maquila_list</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.act_window" id="act_maquila_form">
|
||||
<field name="name">Maquila</field>
|
||||
<field name="res_model">agronomics.maquila</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_maquila_tree_view1">
|
||||
<field name="sequence" eval="10"/>
|
||||
<field name="view" ref="maquila_view_tree"/>
|
||||
<field name="act_window" ref="act_maquila_form"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_maquila_tree_view2">
|
||||
<field name="sequence" eval="20"/>
|
||||
<field name="view" ref="maquila_view_form"/>
|
||||
<field name="act_window" ref="act_maquila_form"/>
|
||||
</record>
|
||||
|
||||
<menuitem parent="menu_maquila" sequence="30"
|
||||
action="act_maquila_form" id="menu_maquila_list"/>
|
||||
|
||||
<record model="ir.model.access" id="access_maquila">
|
||||
<field name="model" search="[('model', '=', 'agronomics.maquila')]"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="False"/>
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_delete" eval="False"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_maquila_agronomics">
|
||||
<field name="model" search="[('model', '=', 'agronomics.maquila')]"/>
|
||||
<field name="group" ref="agronomics.group_agronomics"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_maquila_admin">
|
||||
<field name="model" search="[('model', '=', 'agronomics.maquila')]"/>
|
||||
<field name="group" ref="agronomics.group_agronomics_admin"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.rule.group" id="rule_group_maquila_companies">
|
||||
<field name="name">User in companies</field>
|
||||
<field name="model" search="[('model', '=', 'agronomics.maquila')]"/>
|
||||
<field name="global_p" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.rule" id="rule_maquila_companies">
|
||||
<field name="domain"
|
||||
eval="[('company', 'in', Eval('companies', []))]"
|
||||
pyson="1"/>
|
||||
<field name="rule_group" ref="rule_group_maquila_companies"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.act_window" id="act_maquila_weighing_form2">
|
||||
<field name="name">Weighings</field>
|
||||
<field name="res_model">agronomics.weighing</field>
|
||||
<field name="domain"
|
||||
eval="[If(Eval('active_ids', []) == [Eval('active_id')], ('maquila', '=', Eval('active_id')), ('maquila', 'in', Eval('active_ids')))]"
|
||||
pyson="1"/>
|
||||
</record>
|
||||
<record model="ir.action.keyword" id="act_open_maquila_weighing_keyword1">
|
||||
<field name="keyword">form_relate</field>
|
||||
<field name="model">agronomics.maquila,-1</field>
|
||||
<field name="action" ref="act_maquila_weighing_form2"/>
|
||||
</record>
|
||||
<record model="ir.action-res.group" id="act_maquila_weighing_form2-group_agronomics">
|
||||
<field name="action" ref="act_maquila_weighing_form2"/>
|
||||
<field name="group" ref="group_agronomics"/>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
34
sale.py
34
sale.py
|
@ -86,36 +86,6 @@ class Sale(metaclass=PoolMeta):
|
|||
'maquila_sale_sequence', company=sale.company.id).get()
|
||||
super().set_number(sales)
|
||||
|
||||
@classmethod
|
||||
def process(cls, sales):
|
||||
pool = Pool()
|
||||
Maquila = pool.get('agronomics.maquila')
|
||||
Line = pool.get('sale.line')
|
||||
|
||||
super().process(sales)
|
||||
|
||||
to_save = []
|
||||
for sale in sales:
|
||||
if not sale.is_maquila:
|
||||
continue
|
||||
|
||||
for line in sale.lines:
|
||||
if line.maquila or not line.maquila_product:
|
||||
continue
|
||||
|
||||
maquila = Maquila()
|
||||
maquila.contract = contract # TODO
|
||||
maquila.crop = weighing.crop # TODO
|
||||
maquila.party = sale.party # TODO
|
||||
maquila.quantity = -1 # TODO negatiu
|
||||
maquila.product = line.maquila_product
|
||||
maquila.unit = line.maquila_product.default_uom
|
||||
maquila.save()
|
||||
line.maquila = maquila
|
||||
to_save.append(line)
|
||||
|
||||
Line.save(to_save)
|
||||
|
||||
|
||||
class SaleLine(metaclass=PoolMeta):
|
||||
__name__ = 'sale.line'
|
||||
|
@ -126,7 +96,9 @@ class SaleLine(metaclass=PoolMeta):
|
|||
'required': Bool(Eval('_parent_sale', {}).get('is_maquila')),
|
||||
'readonly': Eval('sale_state') != 'draft',
|
||||
}, depends=['sale_state'])
|
||||
maquila = fields.Many2One('agronomics.maquila', "Maquila", readonly=True,
|
||||
maquila = fields.Many2One('agronomics.maquila', "Maquila",
|
||||
states={
|
||||
'invisible': ~Bool(Eval('_parent_sale', {}).get('is_maquila')),
|
||||
'required': Bool(Eval('_parent_sale', {}).get('is_maquila')),
|
||||
'readonly': Eval('sale_state') != 'draft',
|
||||
})
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
<page name="product_years">
|
||||
<field name="product_years"/>
|
||||
</page>
|
||||
<page name="maquilas">
|
||||
<field name="maquilas"/>
|
||||
</page>
|
||||
</notebook>
|
||||
<group col="6" colspan="6" id="server_buttons">
|
||||
<label name="state"/>
|
||||
|
|
|
@ -7,4 +7,6 @@
|
|||
<field name="table"/>
|
||||
<field name="state"/>
|
||||
<field name="company"/>
|
||||
<field name="product_years" tree_invisible="1"/>
|
||||
<field name="maquilas" tree_invisible="1"/>
|
||||
</tree>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<?xml version="1.0"?>
|
||||
<form>
|
||||
<label name="contract"/>
|
||||
<field name="contract"/>
|
||||
<label name="crop"/>
|
||||
<field name="crop"/>
|
||||
<label name="party"/>
|
||||
<field name="party"/>
|
||||
<label name="crop"/>
|
||||
<field name="crop"/>
|
||||
<label name="table"/>
|
||||
<field name="table"/>
|
||||
<label name="product"/>
|
||||
<field name="product"/>
|
||||
<label name="unit"/>
|
||||
|
@ -14,4 +14,6 @@
|
|||
<field name="quantity"/>
|
||||
<label name="company"/>
|
||||
<field name="company"/>
|
||||
<newline/>
|
||||
<field name="contracts" colspan="4"/>
|
||||
</form>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0"?>
|
||||
<tree>
|
||||
<field name="contract"/>
|
||||
<field name="crop"/>
|
||||
<field name="party"/>
|
||||
<field name="crop"/>
|
||||
<field name="table"/>
|
||||
<field name="product"/>
|
||||
<field name="unit"/>
|
||||
<field name="quantity"/>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0"?>
|
||||
<form>
|
||||
<label name="contract"/>
|
||||
<field name="contract" colspan="3"/>
|
||||
<label name="party"/>
|
||||
<field name="party"/>
|
||||
<label name="crop"/>
|
||||
<field name="crop"/>
|
||||
<label name="product"/>
|
||||
|
@ -10,4 +10,6 @@
|
|||
<field name="quantity"/>
|
||||
<label name="unit"/>
|
||||
<field name="unit"/>
|
||||
<newline/>
|
||||
<field name="contracts" colspan="4"/>
|
||||
</form>
|
|
@ -1,8 +1,9 @@
|
|||
<?xml version="1.0"?>
|
||||
<tree>
|
||||
<field name="contract"/>
|
||||
<field name="party"/>
|
||||
<field name="crop"/>
|
||||
<field name="product"/>
|
||||
<field name="quantity"/>
|
||||
<field name="unit"/>
|
||||
<field name="contracts" tree_invisible="1"/>
|
||||
</tree>
|
|
@ -15,6 +15,10 @@
|
|||
<field name="variety"/>
|
||||
<label name="table"/>
|
||||
<field name="table"/>
|
||||
<label name="is_maquila"/>
|
||||
<field name="is_maquila"/>
|
||||
<label name="maquila"/>
|
||||
<field name="maquila"/>
|
||||
<label name="ecological"/>
|
||||
<field name="ecological"/>
|
||||
<group col="6" colspan="4" id="weight">
|
||||
|
@ -31,10 +35,6 @@
|
|||
<field name="quality_test"/>
|
||||
<label name="inventory_move"/>
|
||||
<field name="inventory_move"/>
|
||||
<label name="is_maquila"/>
|
||||
<field name="is_maquila"/>
|
||||
<label name="maquila"/>
|
||||
<field name="maquila"/>
|
||||
<notebook>
|
||||
<page name="plantations">
|
||||
<field name="plantations" colspan="4"/>
|
||||
|
|
28
weighing.py
28
weighing.py
|
@ -1,7 +1,7 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.model import fields, ModelSQL, ModelView, Workflow, sequence_ordered
|
||||
from trytond.pyson import Id, Eval, If
|
||||
from trytond.pyson import Bool, Id, Eval, If
|
||||
from trytond.pool import Pool
|
||||
from trytond.i18n import gettext
|
||||
from trytond.exceptions import UserError
|
||||
|
@ -125,11 +125,19 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
forced_analysis = fields.Boolean('Forced Analysis', readonly=True)
|
||||
inventory_move = fields.Many2One('stock.move', "Inventory Move",
|
||||
readonly=True)
|
||||
is_maquila = fields.Boolean("Is Maquila")
|
||||
maquila = fields.Many2One('agronomics.maquila', "Maquila", readonly=True,
|
||||
is_maquila = fields.Boolean("Is Maquila", states={
|
||||
'readonly': Eval('state').in_(READONLY2),
|
||||
}, depends=['state'])
|
||||
# TODO weighing table is readonly when is draft
|
||||
maquila = fields.Many2One('agronomics.maquila', "Maquila",
|
||||
domain=[
|
||||
('table', '=', Bool(Eval('table', False))),
|
||||
],
|
||||
states={
|
||||
'readonly': Eval('state').in_(READONLY2),
|
||||
'invisible': ~Eval('is_maquila', False),
|
||||
}, depends=['is_maquila'])
|
||||
'required': Eval('is_maquila', False),
|
||||
}, depends=['is_maquila', 'table', 'state'])
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -478,17 +486,7 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
for weighing in weighings:
|
||||
cost_price = Decimal(0)
|
||||
|
||||
if weighing.is_maquila:
|
||||
maquila = Maquila()
|
||||
maquila.contract = contract # TODO
|
||||
maquila.crop = weighing.crop
|
||||
maquila.party = party # TODO
|
||||
maquila.quantity = -1 # TODO negatiu
|
||||
maquila.product = weighing.product
|
||||
maquila.unit = product.default_uom
|
||||
maquila.save()
|
||||
weighing.maquila = maquila
|
||||
elif not weighing.is_maquila and weighing.beneficiaries:
|
||||
if not weighing.is_maquila and weighing.beneficiaries:
|
||||
for beneficiary in weighing.beneficiaries:
|
||||
price_list = ContractProductPriceListTypePriceList.search([
|
||||
('contract', '=', weighing.purchase_contract),
|
||||
|
|
Loading…
Reference in a new issue