From 03cc171eb2a23c67fa17781581993f0f1e45dc1f Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Fri, 13 Jul 2018 02:02:45 +0200 Subject: [PATCH] [IMP] stock_picking_report_valued: Perform related & compute with sudo For avoiding problems if you don't have access to sales orders (stricter warehouse users, inter-company records...). --- .../models/stock_move_line.py | 44 ++++++++++++++----- .../models/stock_picking.py | 22 +++++++--- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/stock_picking_report_valued/models/stock_move_line.py b/stock_picking_report_valued/models/stock_move_line.py index 5679c5a..6d2e6ea 100644 --- a/stock_picking_report_valued/models/stock_move_line.py +++ b/stock_picking_report_valued/models/stock_move_line.py @@ -1,4 +1,4 @@ -# Copyright 2014 Pedro M. Baeza - Tecnativa +# Copyright 2014-2018 Tecnativa - Pedro M. Baeza # Copyright 2015 Antonio Espinosa - Tecnativa # Copyright 2018 Luis M. Ontalba - Tecnativa # Copyright 2016-2018 Carlos Dauden - Tecnativa @@ -12,34 +12,56 @@ class StockMoveLine(models.Model): sale_line = fields.Many2one( related='move_id.sale_line_id', readonly=True, - string='Related order line') + string='Related order line', + related_sudo=True, # See explanation for sudo in compute method + ) currency_id = fields.Many2one( related='sale_line.currency_id', readonly=True, - string='Sale Currency') + string='Sale Currency', + related_sudo=True, + ) sale_tax_id = fields.Many2many( related='sale_line.tax_id', readonly=True, - string='Sale Tax') + string='Sale Tax', + related_sudo=True, + ) sale_price_unit = fields.Float( related='sale_line.price_unit', readonly=True, - string='Sale price unit') + string='Sale price unit', + related_sudo=True, + ) sale_discount = fields.Float( related='sale_line.discount', readonly=True, - string='Sale discount (%)') + string='Sale discount (%)', + related_sudo=True, + ) sale_tax_description = fields.Char( compute='_compute_sale_order_line_fields', - string='Tax Description') + string='Tax Description', + compute_sudo=True, # See explanation for sudo in compute method + ) sale_price_subtotal = fields.Monetary( compute='_compute_sale_order_line_fields', - string='Price subtotal') + string='Price subtotal', + compute_sudo=True, + ) sale_price_tax = fields.Float( compute='_compute_sale_order_line_fields', - string='Taxes') + string='Taxes', + compute_sudo=True, + ) sale_price_total = fields.Monetary( compute='_compute_sale_order_line_fields', - string='Total') + string='Total', + compute_sudo=True, + ) @api.multi def _compute_sale_order_line_fields(self): + """This is computed with sudo for avoiding problems if you don't have + access to sales orders (stricter warehouse users, inter-company + records...). + """ for line in self: taxes = line.sale_tax_id.compute_all( price_unit=line.sale_line.price_reduce, @@ -55,7 +77,7 @@ class StockMoveLine(models.Model): price_tax = taxes['total_included'] - taxes['total_excluded'] line.update({ 'sale_tax_description': ', '.join( - t.description or t.name for t in line.sale_tax_id), + t.name or t.description for t in line.sale_tax_id), 'sale_price_subtotal': taxes['total_excluded'], 'sale_price_tax': price_tax, 'sale_price_total': taxes['total_included'], diff --git a/stock_picking_report_valued/models/stock_picking.py b/stock_picking_report_valued/models/stock_picking.py index ed5afd2..da57ddc 100644 --- a/stock_picking_report_valued/models/stock_picking.py +++ b/stock_picking_report_valued/models/stock_picking.py @@ -1,4 +1,4 @@ -# Copyright 2014 Pedro M. Baeza - Tecnativa +# Copyright 2014-2018 Tecnativa - Pedro M. Baeza # Copyright 2015 Antonio Espinosa - Tecnativa # Copyright 2016 Carlos Dauden - Tecnativa # Copyright 2016 Luis M. Ontalba - Tecnativa @@ -15,19 +15,31 @@ class StockPicking(models.Model): ) currency_id = fields.Many2one( related='sale_id.currency_id', readonly=True, - string='Currency') + string='Currency', + related_sudo=True, # See explanation for sudo in compute method + ) amount_untaxed = fields.Monetary( compute='_compute_amount_all', - string='Untaxed Amount') + string='Untaxed Amount', + compute_sudo=True, # See explanation for sudo in compute method + ) amount_tax = fields.Monetary( compute='_compute_amount_all', - string='Taxes') + string='Taxes', + compute_sudo=True, + ) amount_total = fields.Monetary( compute='_compute_amount_all', - string='Total') + string='Total', + compute_sudo=True, + ) @api.multi def _compute_amount_all(self): + """This is computed with sudo for avoiding problems if you don't have + access to sales orders (stricter warehouse users, inter-company + records...). + """ for pick in self: amount_untaxed = sum(pick.move_line_ids.mapped( 'sale_price_subtotal'))