Price List Type and add new plantation fields

#047773
This commit is contained in:
Raimon Esteve 2022-03-23 11:13:09 +01:00
parent 0ec0ad0bc4
commit 1a55571ae0
13 changed files with 108 additions and 42 deletions

View File

@ -32,6 +32,8 @@ def register():
product.ProductCrop,
product.ProductDO,
product.ProductEcological,
product.ProductPriceListType,
product.PriceList,
product.ProductVariety,
product.Template,
weighing.WeighingCenter,

47
plot.py
View File

@ -4,6 +4,7 @@ from trytond.model import fields, ModelSQL, ModelView
from trytond.pool import Pool
from trytond.i18n import gettext
from trytond.exceptions import UserError
from trytond.transaction import Transaction
class Enclosure(ModelSQL, ModelView):
"Enclosure"
@ -62,11 +63,13 @@ class Plantation(ModelSQL, ModelView):
"Plantation"
__name__ = 'agronomics.plantation'
code = fields.Char('Code', required=True)
party = fields.Many2One('party.party', 'Party', required=True)
code = fields.Char("Code", required=True)
party = fields.Many2One('party.party', "Party", required=True)
enclosures = fields.One2Many('agronomics.enclosure', 'plantation',
'Enclosure')
parcels = fields.One2Many('agronomics.parcel', 'plantation', 'Parcel')
"Enclosure")
parcels = fields.One2Many('agronomics.parcel', 'plantation', "Parcel")
plantation_year = fields.Integer("Plantation Year")
plantation_owner = fields.Many2One('party.party', "Plantation Owner")
def get_rec_name(self, name):
if self.code:
@ -121,20 +124,6 @@ class Parcel(ModelSQL, ModelView):
if self.plantation and self.crop:
return self.plantation.code + ' - ' + self.crop.rec_name
@classmethod
def validate(cls, records):
super().validate(records)
cls.check_percent_beneficiaries(records)
@classmethod
def check_percent_beneficiaries(cls, records):
for record in records:
percent = sum([x.percent for x in record.beneficiaries])
if record.beneficiaries and abs(100 - round(percent, 2)) > 0.0001:
raise UserError(gettext('agronomics.msg_beneficiaris_percent',
crop=record.crop.rec_name,
plantation=record.plantation.rec_name))
def get_all_do(self, name):
return ",".join([x.name for x in self.denomination_origin])
@ -168,7 +157,21 @@ class Beneficiaries(ModelSQL, ModelView):
"Beneficiaries"
__name__ = 'agronomics.beneficiary'
party = fields.Many2One('party.party', 'Beneficiary', required=True)
percent = fields.Float('Percent', digits=(16, 2), required=True)
parcel = fields.Many2One('agronomics.parcel', 'Parcel')
weighing = fields.Many2One('agronomics.weighing', 'Weighing')
party = fields.Many2One('party.party', "Beneficiary", required=True)
parcel = fields.Many2One('agronomics.parcel', "Parcel")
weighing = fields.Many2One('agronomics.weighing', "Weighing")
product_price_list_type = fields.Many2One('product.price_list.type',
"Product Price List Type")
@classmethod
def __register__(cls, module_name):
cursor = Transaction().connection.cursor()
table = cls.__table_handler__(module_name)
sql_table = cls.__table__()
# Migration from #047773
if table.column_exist('percent'):
table.not_null_action('percent', 'remove')
table.drop_column('percent')
super(Beneficiaries, cls).__register__(module_name)

View File

@ -195,3 +195,15 @@ class ProductEcological(ModelSQL):
ondelete='CASCADE', select=True, required=True)
ecological = fields.Many2One('agronomics.ecological', 'Ecological',
ondelete='CASCADE', select=True, required=True)
class ProductPriceListType(ModelSQL, ModelView):
"Product Price List Type"
__name__ = 'product.price_list.type'
name = fields.Char("Name", required=True)
class PriceList(metaclass=PoolMeta):
__name__ = 'product.price_list'
product_price_list_type = fields.Many2One('product.price_list.type',
"Product Price List Type")

View File

@ -224,5 +224,41 @@
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<!-- product.price_list.price -->
<record model="ir.ui.view" id="product_price_list_type_view_form">
<field name="model">product.price_list.type</field>
<field name="type">form</field>
<field name="name">product_price_list_type_form</field>
</record>
<record model="ir.ui.view" id="product_price_list_type_view_tree">
<field name="model">product.price_list.type</field>
<field name="type">tree</field>
<field name="name">product_price_list_type_tree</field>
</record>
<record model="ir.action.act_window" id="act_product_price_list_type_form">
<field name="name">Product Price List Type</field>
<field name="res_model">product.price_list.type</field>
</record>
<record model="ir.action.act_window.view" id="act_product_price_list_type_form_view1">
<field name="sequence" eval="10"/>
<field name="view" ref="product_price_list_type_view_tree"/>
<field name="act_window" ref="act_product_price_list_type_form"/>
</record>
<record model="ir.action.act_window.view" id="act_product_price_list_type_form_view2">
<field name="sequence" eval="20"/>
<field name="view" ref="product_price_list_type_view_form"/>
<field name="act_window" ref="act_product_price_list_type_form"/>
</record>
<menuitem parent="product_price_list.menu_price_list" action="act_product_price_list_type_form"
id="menu_product_price_list_type_form"/>
<!-- product.price_list -->
<record model="ir.ui.view" id="price_list_view_form">
<field name="model">product.price_list</field>
<field name="inherit" ref="product_price_list.price_list_view_form"/>
<field name="name">price_list_form</field>
</record>
</data>
</tryton>

View File

@ -6,6 +6,7 @@ depends:
party
product_classification
product_classification_taxonomic
product_price_list
product_template_form_quantity
quality_control
purchase_contract

View File

@ -1,8 +1,8 @@
<form>
<label name="party"/>
<field name="party"/>
<label name="percent"/>
<field name="percent"/>
<label name="product_price_list_type"/>
<field name="product_price_list_type"/>
<label name="parcel"/>
<field name="parcel"/>
</form>

View File

@ -1,4 +1,4 @@
<tree editable="1">
<field name="party"/>
<field name="percent"/>
<field name="product_price_list_type"/>
</tree>

View File

@ -3,6 +3,10 @@
<field name="code"/>
<label name="party"/>
<field name="party"/>
<label name="plantation_year"/>
<field name="plantation_year"/>
<label name="plantation_owner"/>
<field name="plantation_owner"/>
<notebook>
<page name="parcels">
<field name="parcels" widget="many2many"/>

View File

@ -1,4 +1,6 @@
<tree>
<field name="code"/>
<field name="party"/>
<field name="plantation_year" tree_invisible="1"/>
<field name="plantation_owner" tree_invisible="1"/>
</tree>

9
view/price_list_form.xml Normal file
View File

@ -0,0 +1,9 @@
<?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="//field[@name='unit']" position="after">
<label name="product_price_list_type"/>
<field name="product_price_list_type"/>
</xpath>
</data>

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. -->
<form>
<label name="name"/>
<field name="name"/>
</form>

View File

@ -0,0 +1,6 @@
<?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>
<field name="name"/>
</tree>

View File

@ -262,22 +262,6 @@ class Weighing(Workflow, ModelSQL, ModelView):
def on_change_with_netweight(self):
return (self.weight or 0) - (self.tara or 0)
@classmethod
def validate(cls, records):
super().validate(records)
cls.check_percent_beneficiaries(records)
@classmethod
def check_percent_beneficiaries(cls, records):
for record in records:
if record.state == 'draft':
continue
percent = sum([x.percent for x in record.beneficiaries])
if record.beneficiaries and abs(100 - round(percent, 2)) > 0.0001:
raise UserError(gettext('agronomics.msg_beneficiaris_percent',
crop=record.crop.rec_name,
plantation=record.plantations[0].plantation.rec_name))
@classmethod
@Workflow.transition('in_analysis')
def analysis(cls, weighings):
@ -426,7 +410,7 @@ class Weighing(Workflow, ModelSQL, ModelView):
b = Beneficiary()
b.party = ben.party
b.weighing = weighing
b.percent = ben.percent
b.product_price_list_type = ben.product_price_list_type
to_save.append(b)
if to_save: