mirror of
https://github.com/OCA/stock-logistics-reporting.git
synced 2025-02-16 17:13:21 +02:00
[IMP] stock_picking_report_valued: Improve code
This commit is contained in:
committed by
Sergio Teruel
parent
98e3a6c394
commit
25c8a36a0b
@@ -1,3 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import models
|
||||
|
||||
@@ -1,61 +1,62 @@
|
||||
# Copyright 2014 Pedro M. Baeza - Tecnativa <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2015 Antonio Espinosa - Tecnativa <antonio.espinosa@tecnativa.com>
|
||||
# Copyright 2016 Carlos Dauden - Tecnativa <carlos.dauden@tecnativa.com>
|
||||
# Copyright 2018 Luis M. Ontalba - Tecnativa <luis.martinez@tecnativa.com>
|
||||
# Copyright 2016-2018 Carlos Dauden - Tecnativa <carlos.dauden@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class StockMoveLine(models.Model):
|
||||
_inherit = "stock.move.line"
|
||||
_inherit = 'stock.move.line'
|
||||
|
||||
currency_id = fields.Many2one(
|
||||
related='sale_line.currency_id', readonly=True,
|
||||
string='Currency')
|
||||
sale_line = fields.Many2one(
|
||||
related='move_id.sale_line_id', readonly=True,
|
||||
string="Related order line")
|
||||
sale_tax_description = fields.Char(
|
||||
compute='_compute_sale_tax_description',
|
||||
string='Tax Description')
|
||||
string='Related order line')
|
||||
currency_id = fields.Many2one(
|
||||
related='sale_line.currency_id', readonly=True,
|
||||
string='Sale Currency')
|
||||
sale_tax_id = fields.Many2many(
|
||||
related='sale_line.tax_id', readonly=True,
|
||||
string='Sale Tax')
|
||||
sale_price_unit = fields.Float(
|
||||
related='sale_line.price_unit', readonly=True,
|
||||
string="Sale price unit")
|
||||
string='Sale price unit')
|
||||
sale_discount = fields.Float(
|
||||
related='sale_line.discount', readonly=True,
|
||||
string="Sale discount (%)")
|
||||
string='Sale discount (%)')
|
||||
sale_tax_description = fields.Char(
|
||||
compute='_compute_sale_order_line_fields',
|
||||
string='Tax Description')
|
||||
sale_price_subtotal = fields.Monetary(
|
||||
compute='_compute_amount',
|
||||
string="Price subtotal")
|
||||
compute='_compute_sale_order_line_fields',
|
||||
string='Price subtotal')
|
||||
sale_price_tax = fields.Float(
|
||||
compute='_compute_amount',
|
||||
compute='_compute_sale_order_line_fields',
|
||||
string='Taxes')
|
||||
sale_price_total = fields.Monetary(
|
||||
compute='_compute_sale_order_line_fields',
|
||||
string='Total')
|
||||
|
||||
@api.multi
|
||||
@api.depends('sale_line.tax_id')
|
||||
def _compute_sale_tax_description(self):
|
||||
def _compute_sale_order_line_fields(self):
|
||||
for line in self:
|
||||
line.sale_tax_description = ', '.join([(
|
||||
x.description or x.name) for x in line.sale_line.tax_id])
|
||||
|
||||
@api.depends('product_uom_qty', 'sale_discount', 'sale_price_unit',
|
||||
'sale_line.tax_id')
|
||||
def _compute_amount(self):
|
||||
for line in self:
|
||||
price = line.sale_price_unit * (1 - (
|
||||
line.sale_discount or 0.0) / 100.0)
|
||||
if line.picking_id.state == 'done':
|
||||
qty = line.qty_done
|
||||
else:
|
||||
qty = line.product_uom_qty
|
||||
taxes = line.sale_line.tax_id.compute_all(
|
||||
price,
|
||||
line.currency_id, qty,
|
||||
product=line.sale_line.product_id,
|
||||
taxes = line.sale_tax_id.compute_all(
|
||||
price_unit=line.sale_line.price_reduce,
|
||||
currency=line.currency_id,
|
||||
quantity=line.qty_done or line.product_qty,
|
||||
product=line.product_id,
|
||||
partner=line.sale_line.order_id.partner_shipping_id)
|
||||
if line.sale_line.company_id.tax_calculation_rounding_method == (
|
||||
'round_globally'):
|
||||
price_tax = sum(
|
||||
t.get('amount', 0.0) for t in taxes.get('taxes', []))
|
||||
else:
|
||||
price_tax = taxes['total_included'] - taxes['total_excluded']
|
||||
line.update({
|
||||
'sale_price_tax': sum(
|
||||
t.get('amount', 0.0) for t in taxes.get('taxes', [])),
|
||||
'sale_tax_description': ', '.join(
|
||||
t.description or t.name for t in line.sale_tax_id),
|
||||
'sale_price_subtotal': taxes['total_excluded'],
|
||||
'sale_price_tax': price_tax,
|
||||
'sale_price_total': taxes['total_included'],
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="view_partner_valued_picking">
|
||||
|
||||
Reference in New Issue
Block a user