diff --git a/__init__.py b/__init__.py index 1860311..9856290 100644 --- a/__init__.py +++ b/__init__.py @@ -32,6 +32,8 @@ def register(): product.ProductCrop, product.ProductDO, product.ProductEcological, + product.ProductPriceListType, + product.PriceList, product.ProductVariety, product.Template, weighing.WeighingCenter, diff --git a/plot.py b/plot.py index 0ad494f..6fecf6b 100644 --- a/plot.py +++ b/plot.py @@ -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) diff --git a/product.py b/product.py index 8a6df98..058cd65 100644 --- a/product.py +++ b/product.py @@ -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") diff --git a/product.xml b/product.xml index 5603e0d..9623f4a 100644 --- a/product.xml +++ b/product.xml @@ -224,5 +224,41 @@ + + + + product.price_list.type + form + product_price_list_type_form + + + product.price_list.type + tree + product_price_list_type_tree + + + + Product Price List Type + product.price_list.type + + + + + + + + + + + + + + + + product.price_list + + price_list_form + diff --git a/tryton.cfg b/tryton.cfg index 31f6ff4..4c715c0 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -6,6 +6,7 @@ depends: party product_classification product_classification_taxonomic + product_price_list product_template_form_quantity quality_control purchase_contract diff --git a/view/beneficiary_form.xml b/view/beneficiary_form.xml index d87b709..b55cb3b 100644 --- a/view/beneficiary_form.xml +++ b/view/beneficiary_form.xml @@ -1,8 +1,8 @@