From bc67e6bf5520e28d2632ae700bbe1ef92e7dda6b Mon Sep 17 00:00:00 2001 From: Robin Heinz Date: Wed, 7 Oct 2020 10:19:43 +0000 Subject: [PATCH] [IMP] point_of_sale: Add serial number on pos invoice When we make an invoice with the point of sale, we now include the serial numbers on the invoice template if the option is ticked. closes odoo/odoo#59516 Task-id: 2349339 Related: odoo/upgrade#1830 Signed-off-by: pimodoo --- addons/point_of_sale/models/account_move.py | 23 +++++++++++++++++++ addons/sale_stock/__manifest__.py | 1 - addons/sale_stock/models/account_move.py | 6 +++-- .../sale_stock/models/res_config_settings.py | 2 -- .../security/sale_stock_security.xml | 5 ---- .../views/res_config_settings_views.xml | 13 ----------- addons/stock_account/__manifest__.py | 1 + addons/stock_account/models/account_move.py | 3 +++ .../models/res_config_settings.py | 2 ++ .../security/stock_account_security.xml | 6 ++++- .../views/report_invoice.xml | 4 ++-- .../views/res_config_settings_views.xml | 11 +++++++++ 12 files changed, 51 insertions(+), 26 deletions(-) rename addons/{sale_stock => stock_account}/views/report_invoice.xml (84%) diff --git a/addons/point_of_sale/models/account_move.py b/addons/point_of_sale/models/account_move.py index c23902ec113..e66bc2e188d 100644 --- a/addons/point_of_sale/models/account_move.py +++ b/addons/point_of_sale/models/account_move.py @@ -23,6 +23,29 @@ class AccountMove(models.Model): for invoice in pos_invoices: invoice.payment_state = 'paid' + def _get_invoiced_lot_values(self): + self.ensure_one() + + lot_values = super(AccountMove, self)._get_invoiced_lot_values() + + if self.state == 'draft': + return lot_values + + for order in self.pos_order_ids: + for line in order.lines: + lots = line.pack_lot_ids or False + if lots: + for lot in lots: + lot_values.append({ + 'product_name': lot.product_id.name, + 'quantity': line.qty if lot.product_id.tracking == 'lot' else 1.0, + 'uom_name': line.product_uom_id.name, + 'lot_name': lot.lot_name, + }) + + return lot_values + + class AccountMoveLine(models.Model): _inherit = 'account.move.line' diff --git a/addons/sale_stock/__manifest__.py b/addons/sale_stock/__manifest__.py index 638753a08d0..a9e0c9ab14e 100644 --- a/addons/sale_stock/__manifest__.py +++ b/addons/sale_stock/__manifest__.py @@ -28,7 +28,6 @@ Preferences 'views/res_config_settings_views.xml', 'views/sale_stock_portal_template.xml', 'views/stock_production_lot_views.xml', - 'views/report_invoice.xml', 'views/res_users_views.xml', 'report/report_stock_forecasted.xml', 'report/sale_order_report_templates.xml', diff --git a/addons/sale_stock/models/account_move.py b/addons/sale_stock/models/account_move.py index 233e4882b98..07488bce8a1 100644 --- a/addons/sale_stock/models/account_move.py +++ b/addons/sale_stock/models/account_move.py @@ -26,8 +26,10 @@ class AccountMove(models.Model): """ Get and prepare data to show a table of invoiced lot on the invoice's report. """ self.ensure_one() + res = super(AccountMove, self)._get_invoiced_lot_values() + if self.state == 'draft': - return [] + return res sale_orders = self.mapped('invoice_line_ids.sale_line_ids.order_id') stock_move_lines = sale_orders.mapped('picking_ids.move_lines.move_line_ids') @@ -86,7 +88,7 @@ class AccountMove(models.Model): qties_per_lot[ml.lot_id] += ml.product_uom_id._compute_quantity(ml.qty_done, ml.product_id.uom_id) for ml in incoming_sml: qties_per_lot[ml.lot_id] -= ml.product_uom_id._compute_quantity(ml.qty_done, ml.product_id.uom_id) - lot_values = [] + lot_values = res for lot_id, qty in qties_per_lot.items(): if float_is_zero(qty, precision_rounding=lot_id.product_id.uom_id.rounding): continue diff --git a/addons/sale_stock/models/res_config_settings.py b/addons/sale_stock/models/res_config_settings.py index e0057775095..981c4bad311 100644 --- a/addons/sale_stock/models/res_config_settings.py +++ b/addons/sale_stock/models/res_config_settings.py @@ -9,8 +9,6 @@ class ResConfigSettings(models.TransientModel): security_lead = fields.Float(related='company_id.security_lead', string="Security Lead Time", readonly=False) group_display_incoterm = fields.Boolean("Incoterms", implied_group='sale_stock.group_display_incoterm') - group_lot_on_invoice = fields.Boolean("Display Lots & Serial Numbers on Invoices", - implied_group='sale_stock.group_lot_on_invoice') use_security_lead = fields.Boolean( string="Security Lead Time for Sales", config_parameter='sale_stock.use_security_lead', diff --git a/addons/sale_stock/security/sale_stock_security.xml b/addons/sale_stock/security/sale_stock_security.xml index e1860aa85fe..e9b95f5328e 100644 --- a/addons/sale_stock/security/sale_stock_security.xml +++ b/addons/sale_stock/security/sale_stock_security.xml @@ -5,11 +5,6 @@ - - Display Serial & Lot Number on Invoices - - - diff --git a/addons/sale_stock/views/res_config_settings_views.xml b/addons/sale_stock/views/res_config_settings_views.xml index 5b2855cd2db..0b038733387 100644 --- a/addons/sale_stock/views/res_config_settings_views.xml +++ b/addons/sale_stock/views/res_config_settings_views.xml @@ -32,19 +32,6 @@ res.config.settings -
-
-
- -
-
-
-
-
diff --git a/addons/stock_account/__manifest__.py b/addons/stock_account/__manifest__.py index 6ec18a56208..a44d99d343a 100644 --- a/addons/stock_account/__manifest__.py +++ b/addons/stock_account/__manifest__.py @@ -31,6 +31,7 @@ Dashboard / Reports for Warehouse Management includes: 'data/product_data.xml', 'views/product_views.xml', 'views/stock_quant_views.xml', + 'views/report_invoice.xml', 'views/stock_valuation_layer_views.xml', 'wizard/stock_valuation_layer_revaluation_views.xml', 'report/report_stock_forecasted.xml', diff --git a/addons/stock_account/models/account_move.py b/addons/stock_account/models/account_move.py index 27828bcae75..8166139af5f 100644 --- a/addons/stock_account/models/account_move.py +++ b/addons/stock_account/models/account_move.py @@ -210,6 +210,9 @@ class AccountMove(models.Model): # Reconcile. product_account_moves.reconcile() + def _get_invoiced_lot_values(self): + return [] + class AccountMoveLine(models.Model): _inherit = 'account.move.line' diff --git a/addons/stock_account/models/res_config_settings.py b/addons/stock_account/models/res_config_settings.py index 0889e5e0983..dac6667ed1a 100644 --- a/addons/stock_account/models/res_config_settings.py +++ b/addons/stock_account/models/res_config_settings.py @@ -9,3 +9,5 @@ class ResConfigSettings(models.TransientModel): module_stock_landed_costs = fields.Boolean("Landed Costs", help="Affect landed costs on reception operations and split them among products to update their cost price.") + group_lot_on_invoice = fields.Boolean("Display Lots & Serial Numbers on Invoices", + implied_group='stock_account.group_lot_on_invoice') diff --git a/addons/stock_account/security/stock_account_security.xml b/addons/stock_account/security/stock_account_security.xml index 1e47996bedc..e641cdeb355 100644 --- a/addons/stock_account/security/stock_account_security.xml +++ b/addons/stock_account/security/stock_account_security.xml @@ -7,5 +7,9 @@ [('company_id', 'in', company_ids)] - + + Display Serial & Lot Number on Invoices + + + diff --git a/addons/sale_stock/views/report_invoice.xml b/addons/stock_account/views/report_invoice.xml similarity index 84% rename from addons/sale_stock/views/report_invoice.xml rename to addons/stock_account/views/report_invoice.xml index 0e12889a24e..6cb65813f00 100644 --- a/addons/sale_stock/views/report_invoice.xml +++ b/addons/stock_account/views/report_invoice.xml @@ -1,11 +1,11 @@ -