From 29c1089717ea6a7e91d2d44fb727a96af72abe0a Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 14 Apr 2015 22:23:00 +0200 Subject: [PATCH] Use display_name instead of an inherit of name_get (better use of new API) Inherit write and create of intrastat codes to remove spaces (patch by Luc De Meyer from Noviat) Add O2M fields from intrastat code to products and product categs --- intrastat_product/intrastat.py | 38 ++++++++++++++++++++-------- intrastat_product/intrastat_view.xml | 6 +++++ 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/intrastat_product/intrastat.py b/intrastat_product/intrastat.py index 13ddd65..efbfe37 100644 --- a/intrastat_product/intrastat.py +++ b/intrastat_product/intrastat.py @@ -29,6 +29,15 @@ class ReportIntrastatCode(models.Model): _name = "report.intrastat.code" _description = "H.S. Code" _order = "name" + _rec_name = "display_name" + + @api.one + @api.depends('name', 'description') + def _compute_display_name(self): + display_name = self.name or '' + if self.description: + display_name += ' ' + self.description + self.display_name = display_name name = fields.Char( string='H.S. code', @@ -37,6 +46,8 @@ class ReportIntrastatCode(models.Model): "http://www.wcoomd.org") description = fields.Char( 'Description', help="Short text description of the H.S. category") + display_name = fields.Char( + compute='_compute_display_name', string="Display Name", readonly=True) intrastat_code = fields.Char( string='European Intrastat Code', size=9, required=True, help="Code used for the Intrastat declaration. Must be part " @@ -49,16 +60,10 @@ class ReportIntrastatCode(models.Model): "this particular Intrastat Code (other than the weight in Kg). " "If no particular unit of measure is required, leave empty.") active = fields.Boolean(default=True) - - @api.multi - def name_get(self): - res = [] - for code in self: - name = code.name - if code.description: - name = u'%s %s' % (name, code.description) - res.append((code.id, name)) - return res + product_categ_ids = fields.One2many( + 'product.category', 'intrastat_id', string='Product Categories') + product_tmpl_ids = fields.One2many( + 'product.template', 'intrastat_id', string='Products') @api.constrains('name', 'intrastat_code') def _hs_code(self): @@ -84,6 +89,19 @@ class ReportIntrastatCode(models.Model): 'This H.S. code already exists in Odoo !' )] + @api.model + @api.returns('self', lambda value: value.id) + def create(self, vals): + if vals.get('intrastat_code'): + vals['intrastat_code'] = vals['intrastat_code'].replace(' ', '') + return super(ReportIntrastatCode, self).create(vals) + + @api.multi + def write(self, vals): + if vals.get('intrastat_code'): + vals['intrastat_code'] = vals['intrastat_code'].replace(' ', '') + return super(ReportIntrastatCode, self).write(vals) + class ProductTemplate(models.Model): _inherit = "product.template" diff --git a/intrastat_product/intrastat_view.xml b/intrastat_product/intrastat_view.xml index da54ba6..b62c280 100644 --- a/intrastat_product/intrastat_view.xml +++ b/intrastat_product/intrastat_view.xml @@ -75,6 +75,12 @@ + + + + + +