Create new model agronomics.contract and agronomics.contract.line.

Use this model instead of purchase_contract in agronomics.weighing.

Task #047246
This commit is contained in:
Juanjo Garcia 2022-03-28 11:42:22 +02:00
parent 3dcbfe618d
commit 5f2e65a417
12 changed files with 315 additions and 185 deletions

View File

@ -15,8 +15,9 @@ from . import price_list
def register():
Pool.register(
contract.PurchaseContract,
contract.PurchaseContractLine,
contract.AgronomicsContractProductPriceListTypePriceList,
contract.AgronomicsContract,
contract.AgronomicsContractLine,
party.Party,
plot.Enclosure,
plot.Crop,

View File

@ -1,6 +1,6 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.model import fields, Workflow, ModelView
from trytond.model import fields, Workflow, ModelView, ModelSQL
from trytond.pool import PoolMeta
from trytond.pyson import Eval
from decimal import Decimal
@ -11,29 +11,102 @@ _STATES = {
_DEPENDS = ['state']
class PurchaseContract(metaclass=PoolMeta):
__name__ = 'purchase.contract'
class AgronomicsContractProductPriceListTypePriceList(ModelSQL, ModelView):
"Agronomics Contract Product Price List Type Price List"
__name__ = 'agronomics.contract-product.price_list.type-product.price_list'
producer = fields.Many2One('party.party', "Producer",
states=_STATES, depends=_DEPENDS)
crop = fields.Many2One('agronomics.crop', "Crop",
states=_STATES, depends=_DEPENDS)
price_list_base = fields.Many2One('product.price_list', "Price List Base",
states=_STATES, depends=_DEPENDS)
price_list_complement = fields.Many2One('product.price_list',
"Price List Complement", states=_STATES, depends=_DEPENDS)
contract = fields.Many2One('agronomics.contract', "Contract")
price_list_type = fields.Many2One(
'product.price_list.type', "Price List Type")
price_list = fields.Many2One('product.price_list', "Price List")
class AgronomicsContract(Workflow, ModelSQL, ModelView):
"Agronomics Contract"
__name__ = 'agronomics.contract'
reference = fields.Char('Reference')
state = fields.Selection([
('draft', 'Draft'),
('active', 'Active'),
('cancelled', "Cancelled"),
('done', 'Done'),
], 'State', readonly=True, required=True)
crop = fields.Many2One(
'agronomics.crop', "Crop", states=_STATES, depends=_DEPENDS,
required=True)
start_date = fields.Function(
fields.Date('Start Date'), 'on_change_with_start_date')
end_date = fields.Function(
fields.Date('End Date'), 'on_change_with_start_date')
producer = fields.Many2One(
'party.party', "Producer", states=_STATES, depends=_DEPENDS,
required=True)
price_list_types = fields.One2Many(
'agronomics.contract-product.price_list.type-product.price_list',
'contract', "Price List Types", states=_STATES, depends=_DEPENDS)
lines = fields.One2Many(
'agronomics.contract.line', 'contract', "Lines", states=_STATES,
depends=_DEPENDS)
weighings = fields.One2Many('agronomics.weighing', 'purchase_contract',
"Weighings", readonly=True)
@classmethod
def __setup__(cls):
super(PurchaseContract, cls).__setup__()
cls.state.selection += [('done', 'Done')]
cls._transitions.add(('active', 'done'))
super(AgronomicsContract, cls).__setup__()
cls._transitions |= set((
('draft', 'active'),
('active', 'cancelled'),
('active', 'done'),
))
cls._buttons.update({
'active': {
'invisible': Eval('state') != 'draft',
'icon': 'tryton-forward',
},
'cancel': {
'invisible': Eval('state') != 'active',
'icon': 'tryton-cancel',
},
'done': {
'invisible': Eval('state') != 'active',
'icon': 'tryton-ok',
}
})
},
})
@staticmethod
def default_state():
return 'draft'
def get_rec_name(self, name):
ret = self.producer.rec_name
if self.start_date:
ret += ' - %s' % (self.start_date)
return ret
@fields.depends('crop')
def on_change_with_start_date(self, name=None):
if self.crop:
return self.crop.start_date
return None
@fields.depends('crop')
def on_change_with_end_date(self, name=None):
if self.crop:
return self.crop.end_date
return None
@classmethod
@ModelView.button
@Workflow.transition('active')
def active(cls, contracts):
pass
@classmethod
@ModelView.button
@Workflow.transition('cancelled')
def cancel(cls, contracts):
pass
@classmethod
@ModelView.button
@ -42,27 +115,63 @@ class PurchaseContract(metaclass=PoolMeta):
pass
class PurchaseContractLine(metaclass=PoolMeta):
__name__ = 'purchase.contract.line'
class AgronomicsContractLine(ModelSQL, ModelView):
"Agronomics Contract Line"
__name__ = 'agronomics.contract.line'
contract = fields.Many2One('agronomics.contract', 'Contract', required=True,
ondelete='CASCADE')
parcel = fields.Many2One('agronomics.parcel', "Parcel",
domain=[
('producer', '=', Eval('_parent_contract.producer')),
('crop', '=', Eval('_parent_contract.crop'))
])
parcel_product = fields.Many2One('product.template', "Parcel Product")
purchased_quantity = fields.Float("Purchased Quantity", digits=(16, 2))
remaining_quantity = fields.Float("Remaining Quantity", digits=(16, 2))
product = fields.Function(
fields.Many2One('product.template', "Product"),
'on_change_with_product')
unit = fields.Function(fields.Many2One('product.uom', "Unit"),
'on_change_with_unit')
unit_digits = fields.Function(fields.Integer("Unit Digits"),
'on_change_with_unit_digits')
agreed_quantity = fields.Float("Agreed Quantity",
digits=(16, Eval('unit_digits', 2)), depends=['unit_digits'])
purchased_quantity = fields.Function(
fields.Float("Purchased Quantity", digits=(16, Eval('unit_digits', 2)),
depends=['unit_digits']),'on_change_with_purchased_quantity')
remaining_quantity = fields.Function(
fields.Float("Remaining Quantity", digits=(16, Eval('unit_digits', 2)),
depends=['unit_digits']), 'on_change_with_remaining_quantity')
@fields.depends('parcel', 'product', 'purchased_quantity',
'remaining_quantity')
def on_change_parcel(self, name=None):
@fields.depends('parcel')
def on_change_with_product(self, name=None):
if self.parcel:
return self.parcel.product.id
return None
@fields.depends('product', methods=['on_change_with_product'])
def on_change_with_unit(self, name=None):
if self.product:
return self.product.purchase_uom.id
return None
@fields.depends('unit')
def on_change_with_unit_digits(self, name=None):
if self.unit:
return self.unit.digits
return 2
@fields.depends('parcel')
def on_change_with_purchased_quantity(self, name=None):
if self.parcel:
if self.parcel.product:
self.parcel_product = self.parcel.product
if self.parcel.purchased_quantity:
self.purchased_quantity = (self.parcel.purchased_quantity
or Decimal(0))
if self.parcel.remaining_quantity:
self.remaining_quantity = (self.parcel.remaining_quantity
or Decimal(0))
return self.parcel.purchased_quantity
return Decimal(0)
@fields.depends('agreed_quantity', 'purchased_quantity')
def on_change_with_remaining_quantity(self, name=None):
if self.agreed_quantity:
if self.purchased_quantity:
return self.agreed_quantity - self.purchased_quantity
else:
return self.agreed_quantity
return None

View File

@ -3,37 +3,109 @@
this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<!-- purchase.contract -->
<record model="ir.ui.view" id="contract_view_form">
<field name="model">purchase.contract</field>
<field name="inherit" ref="purchase_contract.contract_view_form"/>
<!-- agronomics.contract -->
<record model="ir.ui.view" id="agronomics_contract_view_form">
<field name="model">agronomics.contract</field>
<field name="type">form</field>
<field name="name">contract_form</field>
</record>
<record model="ir.ui.view" id="contract_view_tree">
<field name="model">purchase.contract</field>
<field name="inherit" ref="purchase_contract.contract_view_tree"/>
<record model="ir.ui.view" id="agronomics_contract_view_tree">
<field name="model">agronomics.contract</field>
<field name="type">tree</field>
<field name="name">contract_tree</field>
</record>
<!-- purchase.contract.line -->
<record model="ir.ui.view" id="contract_line_view_form">
<field name="model">purchase.contract.line</field>
<field name="inherit" ref="purchase_contract.contract_line_view_form"/>
<record model="ir.action.act_window" id="act_agronomics_contract_action">
<field name="name">Agronomics Contract</field>
<field name="res_model">agronomics.contract</field>
</record>
<record model="ir.action.act_window.view" id="act_agronomics_contract_form_view">
<field name="sequence" eval="10"/>
<field name="view" ref="agronomics_contract_view_tree"/>
<field name="act_window" ref="act_agronomics_contract_action"/>
</record>
<record model="ir.action.act_window.view" id="act_agronomics_contract_tree_view">
<field name="sequence" eval="20"/>
<field name="view" ref="agronomics_contract_view_form"/>
<field name="act_window" ref="act_agronomics_contract_action"/>
</record>
<menuitem parent="menu_agronomics" sequence="10"
action="act_agronomics_contract_action" id="menu_agronomics_contract_list"/>
<record model="ir.action.act_window.domain" id="act_agronomics_contract_draft">
<field name="name">Draft</field>
<field name="sequence" eval="10"/>
<field name="domain" eval="[('state', '=', 'draft')]" pyson="1"/>
<field name="act_window" ref="act_agronomics_contract_action"/>
</record>
<record model="ir.action.act_window.domain" id="act_agronomics_contract_active">
<field name="name">Active</field>
<field name="sequence" eval="20"/>
<field name="domain" eval="[('state', '=', 'active')]" pyson="1"/>
<field name="act_window" ref="act_agronomics_contract_action"/>
</record>
<record model="ir.action.act_window.domain" id="act_agronomics_contract_all">
<field name="name">All</field>
<field name="sequence" eval="30"/>
<field name="domain"/>
<field name="act_window" ref="act_agronomics_contract_action"/>
</record>
<!-- agronomics.contract.line -->
<record model="ir.ui.view" id="agronomics_contract_line_view_form">
<field name="model">agronomics.contract.line</field>
<field name="type">form</field>
<field name="name">contract_line_form</field>
</record>
<record model="ir.ui.view" id="contract_line_view_tree">
<field name="model">purchase.contract.line</field>
<field name="inherit" ref="purchase_contract.contract_line_view_tree"/>
<record model="ir.ui.view" id="agronomics_contract_line_view_tree">
<field name="model">agronomics.contract.line</field>
<field name="type">tree</field>
<field name="name">contract_line_tree</field>
</record>
<!-- agronomics.contract-product.price_list.type-product.price_list -->
<record model="ir.ui.view" id="agronomics_contract_product_price_list_type_product_price_list_view_form">
<field name="model">agronomics.contract-product.price_list.type-product.price_list</field>
<field name="type">form</field>
<field name="name">contract_price_list_price_list_type_form</field>
</record>
<record model="ir.ui.view" id="agronomics_contract_product_price_list_type_product_price_list_view_tree">
<field name="model">agronomics.contract-product.price_list.type-product.price_list</field>
<field name="type">tree</field>
<field name="name">contract_price_list_price_list_type_tree</field>
</record>
<!-- ir.model.button -->
<record model="ir.model.button" id="purchase_contract_done_button">
<record model="ir.model.button" id="agronomics_contract_cancel_button">
<field name="name">cancel</field>
<field name="string">Cancel</field>
<field name="model" search="[('model', '=', 'agronomics.contract')]"/>
</record>
<record model="ir.model.button-res.group" id="agronomics_contract_cancel_button_group_agronomics">
<field name="button" ref="agronomics_contract_cancel_button"/>
<field name="group" ref="group_agronomics"/>
</record>
<record model="ir.model.button" id="agronomics_contract_active_button">
<field name="name">active</field>
<field name="string">Active</field>
<field name="model" search="[('model', '=', 'agronomics.contract')]"/>
</record>
<record model="ir.model.button-res.group" id="agronomics_contract_active_button_group_agronomics">
<field name="button" ref="agronomics_contract_active_button"/>
<field name="group" ref="group_agronomics"/>
</record>
<record model="ir.model.button" id="agronomics_contract_done_button">
<field name="name">done</field>
<field name="string">Done</field>
<field name="model" search="[('model', '=', 'purchase.contract')]"/>
<field name="model" search="[('model', '=', 'agronomics.contract')]"/>
</record>
<record model="ir.model.button-res.group" id="purchase_contract_done_button_group_purchase">
<field name="button" ref="purchase_contract_done_button"/>
<field name="group" ref="purchase.group_purchase"/>
<field name="button" ref="agronomics_contract_done_button"/>
<field name="group" ref="group_agronomics"/>
</record>
</data>
</tryton>

View File

@ -1071,38 +1071,6 @@ msgctxt "field:production.template.outputs-product.template,template:"
msgid "Product"
msgstr "Productes"
msgctxt "field:purchase.contract,crop:"
msgid "Crop"
msgstr "Collita"
msgctxt "field:purchase.contract,price_list_base:"
msgid "Price List Base"
msgstr "Tarifa base"
msgctxt "field:purchase.contract,price_list_complement:"
msgid "Price List Complement"
msgstr "Tarifa complements"
msgctxt "field:purchase.contract,producer:"
msgid "Producer"
msgstr "Productor"
msgctxt "field:purchase.contract.line,parcel:"
msgid "Parcel"
msgstr "Parcel·la"
msgctxt "field:purchase.contract.line,parcel_product:"
msgid "Parcel Product"
msgstr "Producte parcel·la"
msgctxt "field:purchase.contract.line,purchased_quantity:"
msgid "Purchased Quantity"
msgstr "Quantitat comprada"
msgctxt "field:purchase.contract.line,remaining_quantity:"
msgid "Remaining Quantity"
msgstr "Quantitat restant"
msgctxt "field:quality.qualitative.test.line,product:"
msgid "Product"
msgstr "Productes"
@ -1403,10 +1371,6 @@ msgctxt ""
msgid "Done"
msgstr "Realitzar"
msgctxt "model:ir.model.button,string:purchase_contract_done_button"
msgid "Done"
msgstr "Realitzat"
msgctxt "model:ir.model.button,string:weighing_cancel_button"
msgid "Cancel"
msgstr "Cancel·lat"
@ -1892,10 +1856,6 @@ msgctxt "selection:production.output.distribution,production_state:"
msgid "Waiting"
msgstr "En espera"
msgctxt "selection:purchase.contract,state:"
msgid "Done"
msgstr "Realitzat"
msgctxt "view:agronomics.weighing:"
msgid "Parcel Distribution"
msgstr "Distribució per parcel·les"

View File

@ -1071,38 +1071,6 @@ msgctxt "field:production.template.outputs-product.template,template:"
msgid "Product"
msgstr "Productos"
msgctxt "field:purchase.contract,crop:"
msgid "Crop"
msgstr "Cosecha"
msgctxt "field:purchase.contract,price_list_base:"
msgid "Price List Base"
msgstr "Tarifa base"
msgctxt "field:purchase.contract,price_list_complement:"
msgid "Price List Complement"
msgstr "Tarifa complementos"
msgctxt "field:purchase.contract,producer:"
msgid "Producer"
msgstr "Productor"
msgctxt "field:purchase.contract.line,parcel:"
msgid "Parcel"
msgstr "Parcela"
msgctxt "field:purchase.contract.line,parcel_product:"
msgid "Parcel Product"
msgstr "Producto parcela"
msgctxt "field:purchase.contract.line,purchased_quantity:"
msgid "Purchased Quantity"
msgstr "Cantidad comprada"
msgctxt "field:purchase.contract.line,remaining_quantity:"
msgid "Remaining Quantity"
msgstr "Cantidad restante"
msgctxt "field:quality.qualitative.test.line,product:"
msgid "Product"
msgstr "Productos"
@ -1405,10 +1373,6 @@ msgctxt ""
msgid "Done"
msgstr "Realizar"
msgctxt "model:ir.model.button,string:purchase_contract_done_button"
msgid "Done"
msgstr "Realizar"
msgctxt "model:ir.model.button,string:weighing_cancel_button"
msgid "Cancel"
msgstr "Cancel·lar"
@ -1894,10 +1858,6 @@ msgctxt "selection:production.output.distribution,production_state:"
msgid "Waiting"
msgstr "En espera"
msgctxt "selection:purchase.contract,state:"
msgid "Done"
msgstr "Realizado"
msgctxt "view:agronomics.weighing:"
msgid "Parcel Distribution"
msgstr "Distribución por parcelas"

View File

@ -1,21 +1,34 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/form/field[@name='end_date']" position="after">
<label name="producer"/>
<field name="producer"/>
<label name="crop"/>
<field name="crop"/>
<label name="price_list_base"/>
<field name="price_list_base"/>
<label name="price_list_complement"/>
<field name="price_list_complement"/>
</xpath>
<xpath expr="/form/group[@id='buttons']" position="replace_attributes">
<group col="5" colspan="4" id="buttons"/>
</xpath>
<xpath expr="/form/group[@id='buttons']/button[@name='cancel']" position="after">
<form>
<label name="reference"/>
<field name="reference"/>
<newline/>
<label name="producer"/>
<field name="producer"/>
<label name="crop"/>
<field name="crop"/>
<label name="start_date"/>
<field name="start_date"/>
<label name="end_date"/>
<field name="end_date"/>
<notebook>
<page name="lines">
<field name="lines" colspan="4"/>
</page>
<page name="price_list_types">
<field name="price_list_types" colspan="4"/>
</page>
<page name="weighings">
<field name="weighings" colspan="4"/>
</page>
</notebook>
<group id="buttons" col="5" colspan="4">
<label name="state"/>
<field name="state"/>
<button name="active"/>
<button name="cancel"/>
<button name="done"/>
</xpath>
</data>
</group>
</form>

View File

@ -1,23 +1,19 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/form/notebook/page[@id='product']/label[@name='agreed_quantity']" position="replace">
</xpath>
<xpath expr="/form/notebook/page[@id='product']/field[@name='agreed_quantity']" position="replace">
</xpath>
<xpath expr="/form/notebook/page[@id='product']/field[@name='consumed_quantity']" position="after">
<newline/>
<separator id="agronomics_fields" colspan="4"/>
<label name="parcel"/>
<field name="parcel"/>
<label name="parcel_product"/>
<field name="parcel_product"/>
<label name="agreed_quantity"/>
<field name="agreed_quantity"/>
<label name="purchased_quantity"/>
<field name="purchased_quantity"/>
<label name="remaining_quantity"/>
<field name="remaining_quantity"/>
</xpath>
</data>
<form>
<label name="parcel"/>
<field name="parcel"/>
<label name="contract"/>
<field name="contract"/>
<label name="product"/>
<field name="product"/>
<label name="unit"/>
<field name="unit"/>
<label name="agreed_quantity"/>
<field name="agreed_quantity"/>
<label name="purchased_quantity"/>
<field name="purchased_quantity"/>
<label name="remaining_quantity"/>
<field name="remaining_quantity"/>
</form>

View File

@ -1,12 +1,11 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/tree" position="inside">
<field name="parcel"/>
<field name="parcel_product"/>
<field name="agreed_quantity"/>
<field name="purchased_quantity"/>
<field name="remaining_quantity"/>
</xpath>
</data>
<tree>
<field name="contract"/>
<field name="parcel"/>
<field name="product"/>
<field name="agreed_quantity"/>
<field name="purchased_quantity"/>
<field name="remaining_quantity"/>
</tree>

View File

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<form>
<label name="contract"/>
<field name="contract"/>
<newline/>
<label name="price_list_type"/>
<field name="price_list_type"/>
<label name="price_list"/>
<field name="price_list"/>
</form>

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tree editable="1">
<field name="price_list_type"/>
<field name="price_list"/>
</tree>

View File

@ -1,9 +1,10 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/tree" position="inside">
<field name="producer"/>
<field name="crop"/>
</xpath>
</data>
<tree>
<field name="reference"/>
<field name="producer"/>
<field name="crop"/>
<field name="start_date"/>
<field name="end_date"/>
</tree>

View File

@ -38,7 +38,7 @@ class Weighing(Workflow, ModelSQL, ModelView):
'required': True
}, depends=['state'])
purchase_contract = fields.Many2One('purchase.contract',
purchase_contract = fields.Many2One('agronomics.contract',
'Purchase Contract', states={
'readonly': Eval('state').in_(READONLY),
'required': True
@ -243,7 +243,7 @@ class Weighing(Workflow, ModelSQL, ModelView):
@fields.depends('plantations')
def on_change_with_purchase_contract(self):
pool = Pool()
ContractLine = pool.get('purchase.contract.line')
ContractLine = pool.get('agronomics.contract.line')
parcel = self.get_parcel()
if not parcel: