diff --git a/ext/custom-addons/dp_custom/models/account.py b/ext/custom-addons/dp_custom/models/account.py index 4fb42989..4d2ff001 100644 --- a/ext/custom-addons/dp_custom/models/account.py +++ b/ext/custom-addons/dp_custom/models/account.py @@ -18,13 +18,17 @@ # along with this program. If not, see . # ############################################################################## -from odoo import api, fields, models +from odoo import api, fields, models, _ +from odoo.exceptions import UserError class AccountInvoiceLine(models.Model): _inherit = 'account.invoice.line' - intrastat_id = fields.Many2one(comodel_name='report.intrastat.code', string='Intrastat Code') + intrastat_id = fields.Many2one(comodel_name='report.intrastat.code', string='Intrastat Code', + compute="_compute_intrastat_id", inverse='_set_intrastat_id') + lot_id = fields.Many2one(comodel_name='stock.production.lot', string='Lot') + weight = fields.Float(string='Gewicht', compute='_compute_weight') @api.model def create(self, vals): @@ -32,6 +36,31 @@ class AccountInvoiceLine(models.Model): vals.update(intrastat_id=self.env['product.template'].browse(vals['product_id']).intrastat_id.id) return super(AccountInvoiceLine, self).create(vals) + @api.multi + def action_show_lot(self): + self.ensure_one() + action = self.env.ref('stock.action_production_lot_form').read()[0] + action['res_id'] = self.lot_id.id + action['view_mode'] = 'form' + action['views'] = [(False, 'form')] + + return action + + def _compute_weight(self): + for record in self: + record.weight = record.lot_id.weight or record.product_id.weight + + 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 + + def _set_intrastat_id(self): + for record in self: + if record.lot_id: + record.lot_id.intrastat_id = record.intrastat_id.id + else: + raise UserError(_('Der Intrastrat Code kann nur gesetzt werden wenn ein Lot angegeben wurde.')) + class AccountPaymentTerm(models.Model): _inherit = 'account.payment.term' @@ -51,7 +80,7 @@ class AccountInvoice(models.Model): for record in self: _sum = 0 for line in record.invoice_line_ids: - _sum += line.product_id.weight * line.quantity + _sum += line.weight * line.quantity record.weight_total = _sum @api.multi @@ -64,7 +93,7 @@ class AccountInvoice(models.Model): for record in self: num_items = 0 for line in record.invoice_line_ids: - if line.uom_id == self.env.ref('product.product_uom_unit'): # wenn die Mengeneinheit Stk. ist + if line.uom_id == self.env.ref('product.product_uom_unit'): # wenn die Mengeneinheit Stk. ist num_items += line.quantity record.num_items = num_items diff --git a/ext/custom-addons/dp_custom/models/sale.py b/ext/custom-addons/dp_custom/models/sale.py index 2deb215f..c6a905be 100644 --- a/ext/custom-addons/dp_custom/models/sale.py +++ b/ext/custom-addons/dp_custom/models/sale.py @@ -56,7 +56,7 @@ class SaleOrder(models.Model): for record in self: _sum = 0 for line in record.order_line: - _sum += (line.lot_id.weight or line.product_id.weight) * line.product_uom_qty + _sum += line.weight * line.product_uom_qty record.weight_total = _sum @api.multi @@ -242,7 +242,8 @@ class SaleOrder(models.Model): @api.model def _get_specified_fields(self): return ['origin', 'client_order_ref', 'note', 'date_order', 'assembled', 'line_id', 'partner_id', - 'fiscal_position_id', 'user_id', 'payment_term_id', 'partner_delivery_id', 'partner_invoice_id', 'assembly_state'] + 'fiscal_position_id', 'user_id', 'payment_term_id', 'partner_delivery_id', 'partner_invoice_id', + 'assembly_state'] @api.multi def write(self, vals): @@ -330,6 +331,9 @@ class SaleOrderLine(models.Model): lot_id = fields.Many2one(comodel_name='stock.production.lot', string='Lot') from_designbox = fields.Boolean(string='Import von Designbox', readonly=True) 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") @api.multi def write(self, vals): @@ -349,3 +353,31 @@ class SaleOrderLine(models.Model): raise ValidationError( _("Produkt \'%s\' kann nicht zugeordnet werden" % vals['product_id'])) return vals + + @api.multi + def action_show_lot(self): + self.ensure_one() + action = self.env.ref('stock.action_production_lot_form').read()[0] + action['res_id'] = self.lot_id.id + action['view_mode'] = 'form' + action['views'] = [(False, 'form')] + + return action + + @api.multi + def _compute_weight(self): + 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() + res = super(SaleOrderLine, self)._prepare_invoice_line(qty) + + res['lot_id'] = self.lot_id.id + return res diff --git a/ext/custom-addons/dp_custom/models/stock.py b/ext/custom-addons/dp_custom/models/stock.py index d380b638..da72d41f 100644 --- a/ext/custom-addons/dp_custom/models/stock.py +++ b/ext/custom-addons/dp_custom/models/stock.py @@ -27,6 +27,7 @@ class StockProductionLot(models.Model): notes = fields.Text() weight = fields.Float(string='Gewicht') + intrastat_id = fields.Many2one(comodel_name='report.intrastat.code', string='Intrastat Nummer (Code)') image = fields.Binary("Produktbild", attachment=True, help="Wenn vorhanden, wird dieses Bild in den Angeboten/Aufträgen angedruckt") image_medium = fields.Binary("Produktbild (resized)", attachment=True, diff --git a/ext/custom-addons/dp_custom/views/account_views.xml b/ext/custom-addons/dp_custom/views/account_views.xml index f97c56ba..72478100 100644 --- a/ext/custom-addons/dp_custom/views/account_views.xml +++ b/ext/custom-addons/dp_custom/views/account_views.xml @@ -9,6 +9,15 @@ + + + +