mirror of
https://github.com/OCA/stock-logistics-reporting.git
synced 2025-02-16 17:13:21 +02:00
[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...).
This commit is contained in:
committed by
Ernesto Tejeda
parent
8192d8aed5
commit
eefb02222e
@@ -1,4 +1,4 @@
|
|||||||
# Copyright 2014 Pedro M. Baeza - Tecnativa <pedro.baeza@tecnativa.com>
|
# Copyright 2014-2018 Tecnativa - Pedro M. Baeza
|
||||||
# Copyright 2015 Antonio Espinosa - Tecnativa <antonio.espinosa@tecnativa.com>
|
# Copyright 2015 Antonio Espinosa - Tecnativa <antonio.espinosa@tecnativa.com>
|
||||||
# Copyright 2018 Luis M. Ontalba - Tecnativa <luis.martinez@tecnativa.com>
|
# Copyright 2018 Luis M. Ontalba - Tecnativa <luis.martinez@tecnativa.com>
|
||||||
# Copyright 2016-2018 Carlos Dauden - Tecnativa <carlos.dauden@tecnativa.com>
|
# Copyright 2016-2018 Carlos Dauden - Tecnativa <carlos.dauden@tecnativa.com>
|
||||||
@@ -12,34 +12,56 @@ class StockMoveLine(models.Model):
|
|||||||
|
|
||||||
sale_line = fields.Many2one(
|
sale_line = fields.Many2one(
|
||||||
related='move_id.sale_line_id', readonly=True,
|
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(
|
currency_id = fields.Many2one(
|
||||||
related='sale_line.currency_id', readonly=True,
|
related='sale_line.currency_id', readonly=True,
|
||||||
string='Sale Currency')
|
string='Sale Currency',
|
||||||
|
related_sudo=True,
|
||||||
|
)
|
||||||
sale_tax_id = fields.Many2many(
|
sale_tax_id = fields.Many2many(
|
||||||
related='sale_line.tax_id', readonly=True,
|
related='sale_line.tax_id', readonly=True,
|
||||||
string='Sale Tax')
|
string='Sale Tax',
|
||||||
|
related_sudo=True,
|
||||||
|
)
|
||||||
sale_price_unit = fields.Float(
|
sale_price_unit = fields.Float(
|
||||||
related='sale_line.price_unit', readonly=True,
|
related='sale_line.price_unit', readonly=True,
|
||||||
string='Sale price unit')
|
string='Sale price unit',
|
||||||
|
related_sudo=True,
|
||||||
|
)
|
||||||
sale_discount = fields.Float(
|
sale_discount = fields.Float(
|
||||||
related='sale_line.discount', readonly=True,
|
related='sale_line.discount', readonly=True,
|
||||||
string='Sale discount (%)')
|
string='Sale discount (%)',
|
||||||
|
related_sudo=True,
|
||||||
|
)
|
||||||
sale_tax_description = fields.Char(
|
sale_tax_description = fields.Char(
|
||||||
compute='_compute_sale_order_line_fields',
|
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(
|
sale_price_subtotal = fields.Monetary(
|
||||||
compute='_compute_sale_order_line_fields',
|
compute='_compute_sale_order_line_fields',
|
||||||
string='Price subtotal')
|
string='Price subtotal',
|
||||||
|
compute_sudo=True,
|
||||||
|
)
|
||||||
sale_price_tax = fields.Float(
|
sale_price_tax = fields.Float(
|
||||||
compute='_compute_sale_order_line_fields',
|
compute='_compute_sale_order_line_fields',
|
||||||
string='Taxes')
|
string='Taxes',
|
||||||
|
compute_sudo=True,
|
||||||
|
)
|
||||||
sale_price_total = fields.Monetary(
|
sale_price_total = fields.Monetary(
|
||||||
compute='_compute_sale_order_line_fields',
|
compute='_compute_sale_order_line_fields',
|
||||||
string='Total')
|
string='Total',
|
||||||
|
compute_sudo=True,
|
||||||
|
)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _compute_sale_order_line_fields(self):
|
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:
|
for line in self:
|
||||||
taxes = line.sale_tax_id.compute_all(
|
taxes = line.sale_tax_id.compute_all(
|
||||||
price_unit=line.sale_line.price_reduce,
|
price_unit=line.sale_line.price_reduce,
|
||||||
@@ -55,7 +77,7 @@ class StockMoveLine(models.Model):
|
|||||||
price_tax = taxes['total_included'] - taxes['total_excluded']
|
price_tax = taxes['total_included'] - taxes['total_excluded']
|
||||||
line.update({
|
line.update({
|
||||||
'sale_tax_description': ', '.join(
|
'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_subtotal': taxes['total_excluded'],
|
||||||
'sale_price_tax': price_tax,
|
'sale_price_tax': price_tax,
|
||||||
'sale_price_total': taxes['total_included'],
|
'sale_price_total': taxes['total_included'],
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Copyright 2014 Pedro M. Baeza - Tecnativa <pedro.baeza@tecnativa.com>
|
# Copyright 2014-2018 Tecnativa - Pedro M. Baeza
|
||||||
# Copyright 2015 Antonio Espinosa - Tecnativa <antonio.espinosa@tecnativa.com>
|
# Copyright 2015 Antonio Espinosa - Tecnativa <antonio.espinosa@tecnativa.com>
|
||||||
# Copyright 2016 Carlos Dauden - Tecnativa <carlos.dauden@tecnativa.com>
|
# Copyright 2016 Carlos Dauden - Tecnativa <carlos.dauden@tecnativa.com>
|
||||||
# Copyright 2016 Luis M. Ontalba - Tecnativa <luis.martinez@tecnativa.com>
|
# Copyright 2016 Luis M. Ontalba - Tecnativa <luis.martinez@tecnativa.com>
|
||||||
@@ -15,19 +15,31 @@ class StockPicking(models.Model):
|
|||||||
)
|
)
|
||||||
currency_id = fields.Many2one(
|
currency_id = fields.Many2one(
|
||||||
related='sale_id.currency_id', readonly=True,
|
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(
|
amount_untaxed = fields.Monetary(
|
||||||
compute='_compute_amount_all',
|
compute='_compute_amount_all',
|
||||||
string='Untaxed Amount')
|
string='Untaxed Amount',
|
||||||
|
compute_sudo=True, # See explanation for sudo in compute method
|
||||||
|
)
|
||||||
amount_tax = fields.Monetary(
|
amount_tax = fields.Monetary(
|
||||||
compute='_compute_amount_all',
|
compute='_compute_amount_all',
|
||||||
string='Taxes')
|
string='Taxes',
|
||||||
|
compute_sudo=True,
|
||||||
|
)
|
||||||
amount_total = fields.Monetary(
|
amount_total = fields.Monetary(
|
||||||
compute='_compute_amount_all',
|
compute='_compute_amount_all',
|
||||||
string='Total')
|
string='Total',
|
||||||
|
compute_sudo=True,
|
||||||
|
)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _compute_amount_all(self):
|
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:
|
for pick in self:
|
||||||
amount_untaxed = sum(pick.move_line_ids.mapped(
|
amount_untaxed = sum(pick.move_line_ids.mapped(
|
||||||
'sale_price_subtotal'))
|
'sale_price_subtotal'))
|
||||||
|
|||||||
Reference in New Issue
Block a user