From 4b9629d9b01a97710039a7e84919271250a0173d Mon Sep 17 00:00:00 2001 From: Ahmed Aly Date: Wed, 18 Apr 2018 12:59:58 +0200 Subject: [PATCH] =?UTF-8?q?Fall=205557:=20=C3=84nderungsw=C3=BCnsche=20vom?= =?UTF-8?q?=20Workshop=20Termin=20am=2012.04.2018?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ext/custom-addons/dp_custom/models/sale.py | 25 +++++++++++++------ .../dp_custom/views/sale_views.xml | 7 ++++++ .../dp_reports_account/reports/invoice.xml | 10 +++++--- .../dp_reports_sale/reports/sale.xml | 12 ++++++--- .../dp_sale_hide_discount/models/account.py | 2 +- .../dp_sale_hide_discount/models/sale.py | 2 +- 6 files changed, 42 insertions(+), 16 deletions(-) diff --git a/ext/custom-addons/dp_custom/models/sale.py b/ext/custom-addons/dp_custom/models/sale.py index 4d7b6456..d93b5c5b 100644 --- a/ext/custom-addons/dp_custom/models/sale.py +++ b/ext/custom-addons/dp_custom/models/sale.py @@ -393,12 +393,28 @@ class SaleOrderLine(models.Model): from_designbox = fields.Boolean(string='I', readonly=True, help='Import von externem System') product_id = fields.Many2one(domain=[('sale_ok', '=', True), ('can_be_sold_unconfigured', '=', True)]) weight = fields.Float(string='Gewicht', compute='_compute_weight') - intrastat_id = fields.Many2one(comodel_name='report.intrastat.code', string='Intrastat Code', - compute="_compute_intrastat_id") + intrastat_id = fields.Many2one(comodel_name='report.intrastat.code', string='Intrastat Code') + + @api.model + def create(self, vals): + if vals.get('intrastat_id', None) is None: + if vals.get('lot_id', False): + vals.update(intrastat_id=self.env['stock.production.lot'].browse(vals['lot_id']).intrastat_id.id) + elif vals.get('product_id', False): + vals.update(intrastat_id=self.env['product.template'].browse(vals['product_id']).intrastat_id.id) + return super(SaleOrderLine, self).create(vals) @api.multi def write(self, vals): for record in self: + lot_id = record.lot_id if 'lot_id' not in vals else vals.get('lot_id', False) + if vals.get('intrastat_id', False) and lot_id: + self.env['stock.production.lot'].browse([vals.get('lot_id', False)]).write({ + 'intrastat_id': vals.get('intrastat_id') + }) + elif vals.get('intrastat_id', False) and not lot_id: + raise UserError(_('Der Intrastrat Code kann nur gesetzt werden wenn ein Lot angegeben wurde.')) + if record.from_designbox and set(vals.keys()).intersection( ['product_uom_qty', 'product_uom', 'price_unit']): raise ValidationError(_("Menge und Preis können von Produkten aus der Designbox nicht geändert werden")) @@ -430,11 +446,6 @@ class SaleOrderLine(models.Model): for record in self: record.weight = record.lot_id.weight or record.product_id.weight - @api.multi - def _compute_intrastat_id(self): - for record in self: - record.intrastat_id = record.lot_id.intrastat_id.id or record.product_id.intrastat_id.id - @api.multi def _prepare_invoice_line(self, qty): self.ensure_one() diff --git a/ext/custom-addons/dp_custom/views/sale_views.xml b/ext/custom-addons/dp_custom/views/sale_views.xml index 1813a065..f6c5496e 100644 --- a/ext/custom-addons/dp_custom/views/sale_views.xml +++ b/ext/custom-addons/dp_custom/views/sale_views.xml @@ -25,10 +25,16 @@ + + + + + +