mirror of
https://github.com/OCA/stock-logistics-reporting.git
synced 2025-02-16 17:13:21 +02:00
[IMP] stock_picking_report_valued: black, isort
This commit is contained in:
@@ -9,18 +9,11 @@
|
||||
"name": "Valued Picking Report",
|
||||
"summary": "Adding Valued Picking on Delivery Slip report",
|
||||
"version": "12.0.1.0.0",
|
||||
"author": "Tecnativa, "
|
||||
"Odoo Community Association (OCA)",
|
||||
"author": "Tecnativa, " "Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/stock-logistics-reporting",
|
||||
"category": "Warehouse Management",
|
||||
"license": "AGPL-3",
|
||||
"depends": [
|
||||
"sale_management",
|
||||
"stock",
|
||||
],
|
||||
"data": [
|
||||
'views/res_partner_view.xml',
|
||||
'report/stock_picking_report_valued.xml',
|
||||
],
|
||||
"depends": ["sale_management", "stock"],
|
||||
"data": ["views/res_partner_view.xml", "report/stock_picking_report_valued.xml"],
|
||||
"installable": True,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
from . import res_partner
|
||||
from . import stock_move_line
|
||||
from . import stock_picking
|
||||
|
||||
@@ -7,9 +7,8 @@ from odoo import fields, models
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
_inherit = "res.partner"
|
||||
|
||||
valued_picking = fields.Boolean(
|
||||
default=True,
|
||||
help='You can select which partners have valued pickings',
|
||||
default=True, help="You can select which partners have valued pickings"
|
||||
)
|
||||
|
||||
@@ -8,47 +8,38 @@ from odoo import api, fields, models
|
||||
|
||||
|
||||
class StockMoveLine(models.Model):
|
||||
_inherit = 'stock.move.line'
|
||||
_inherit = "stock.move.line"
|
||||
|
||||
sale_line = fields.Many2one(
|
||||
related='move_id.sale_line_id', readonly=True,
|
||||
string='Related order line',
|
||||
related="move_id.sale_line_id", readonly=True, string="Related order line"
|
||||
)
|
||||
currency_id = fields.Many2one(
|
||||
related='sale_line.currency_id', readonly=True,
|
||||
string='Sale Currency',
|
||||
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',
|
||||
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',
|
||||
related="sale_line.price_unit", readonly=True, string="Sale price unit"
|
||||
)
|
||||
sale_discount = fields.Float(
|
||||
related='sale_line.discount', readonly=True,
|
||||
string='Sale discount (%)',
|
||||
related="sale_line.discount", readonly=True, string="Sale discount (%)"
|
||||
)
|
||||
sale_tax_description = fields.Char(
|
||||
compute='_compute_sale_order_line_fields',
|
||||
string='Tax Description',
|
||||
compute="_compute_sale_order_line_fields",
|
||||
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',
|
||||
compute="_compute_sale_order_line_fields",
|
||||
string="Price subtotal",
|
||||
compute_sudo=True,
|
||||
)
|
||||
sale_price_tax = fields.Float(
|
||||
compute='_compute_sale_order_line_fields',
|
||||
string='Taxes',
|
||||
compute_sudo=True,
|
||||
compute="_compute_sale_order_line_fields", string="Taxes", compute_sudo=True
|
||||
)
|
||||
sale_price_total = fields.Monetary(
|
||||
compute='_compute_sale_order_line_fields',
|
||||
string='Total',
|
||||
compute_sudo=True,
|
||||
compute="_compute_sale_order_line_fields", string="Total", compute_sudo=True
|
||||
)
|
||||
|
||||
@api.multi
|
||||
@@ -61,23 +52,29 @@ class StockMoveLine(models.Model):
|
||||
sale_line = line.sale_line
|
||||
price_unit = (
|
||||
sale_line.price_subtotal / sale_line.product_uom_qty
|
||||
if sale_line.product_uom_qty else sale_line.price_reduce)
|
||||
if sale_line.product_uom_qty
|
||||
else sale_line.price_reduce
|
||||
)
|
||||
taxes = line.sale_tax_id.compute_all(
|
||||
price_unit=price_unit,
|
||||
currency=line.currency_id,
|
||||
quantity=line.qty_done or line.product_qty,
|
||||
product=line.product_id,
|
||||
partner=sale_line.order_id.partner_shipping_id)
|
||||
partner=sale_line.order_id.partner_shipping_id,
|
||||
)
|
||||
if sale_line.company_id.tax_calculation_rounding_method == (
|
||||
'round_globally'):
|
||||
price_tax = sum(
|
||||
t.get('amount', 0.0) for t in taxes.get('taxes', []))
|
||||
"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_tax_description': ', '.join(
|
||||
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'],
|
||||
})
|
||||
price_tax = taxes["total_included"] - taxes["total_excluded"]
|
||||
line.update(
|
||||
{
|
||||
"sale_tax_description": ", ".join(
|
||||
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"],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -10,28 +10,23 @@ from odoo import api, fields, models
|
||||
class StockPicking(models.Model):
|
||||
_inherit = "stock.picking"
|
||||
|
||||
valued = fields.Boolean(
|
||||
related='partner_id.valued_picking', readonly=True,
|
||||
)
|
||||
valued = fields.Boolean(related="partner_id.valued_picking", readonly=True)
|
||||
currency_id = fields.Many2one(
|
||||
related='sale_id.currency_id', readonly=True,
|
||||
string='Currency',
|
||||
related="sale_id.currency_id",
|
||||
readonly=True,
|
||||
string="Currency",
|
||||
related_sudo=True, # See explanation for sudo in compute method
|
||||
)
|
||||
amount_untaxed = fields.Monetary(
|
||||
compute='_compute_amount_all',
|
||||
string='Untaxed Amount',
|
||||
compute="_compute_amount_all",
|
||||
string="Untaxed Amount",
|
||||
compute_sudo=True, # See explanation for sudo in compute method
|
||||
)
|
||||
amount_tax = fields.Monetary(
|
||||
compute='_compute_amount_all',
|
||||
string='Taxes',
|
||||
compute_sudo=True,
|
||||
compute="_compute_amount_all", string="Taxes", compute_sudo=True
|
||||
)
|
||||
amount_total = fields.Monetary(
|
||||
compute='_compute_amount_all',
|
||||
string='Total',
|
||||
compute_sudo=True,
|
||||
compute="_compute_amount_all", string="Total", compute_sudo=True
|
||||
)
|
||||
|
||||
@api.multi
|
||||
@@ -44,14 +39,15 @@ class StockPicking(models.Model):
|
||||
round_curr = pick.sale_id.currency_id.round
|
||||
amount_tax = 0.0
|
||||
for tax_id, tax_group in pick.get_taxes_values().items():
|
||||
amount_tax += round_curr(tax_group['amount'])
|
||||
amount_untaxed = sum(
|
||||
l.sale_price_subtotal for l in pick.move_line_ids)
|
||||
pick.update({
|
||||
'amount_untaxed': amount_untaxed,
|
||||
'amount_tax': amount_tax,
|
||||
'amount_total': amount_untaxed + amount_tax,
|
||||
})
|
||||
amount_tax += round_curr(tax_group["amount"])
|
||||
amount_untaxed = sum(l.sale_price_subtotal for l in pick.move_line_ids)
|
||||
pick.update(
|
||||
{
|
||||
"amount_untaxed": amount_untaxed,
|
||||
"amount_tax": amount_tax,
|
||||
"amount_total": amount_untaxed + amount_tax,
|
||||
}
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def get_taxes_values(self):
|
||||
@@ -60,14 +56,11 @@ class StockPicking(models.Model):
|
||||
for tax in line.sale_line.tax_id:
|
||||
tax_id = tax.id
|
||||
if tax_id not in tax_grouped:
|
||||
tax_grouped[tax_id] = {
|
||||
'base': line.sale_price_subtotal,
|
||||
'tax': tax,
|
||||
}
|
||||
tax_grouped[tax_id] = {"base": line.sale_price_subtotal, "tax": tax}
|
||||
else:
|
||||
tax_grouped[tax_id]['base'] += line.sale_price_subtotal
|
||||
tax_grouped[tax_id]["base"] += line.sale_price_subtotal
|
||||
for tax_id, tax_group in tax_grouped.items():
|
||||
tax_grouped[tax_id]['amount'] = tax_group['tax'].compute_all(
|
||||
tax_group['base'], self.sale_id.currency_id
|
||||
)['taxes'][0]['amount']
|
||||
tax_grouped[tax_id]["amount"] = tax_group["tax"].compute_all(
|
||||
tax_group["base"], self.sale_id.currency_id
|
||||
)["taxes"][0]["amount"]
|
||||
return tax_grouped
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
|
||||
from . import test_stock_picking_valued
|
||||
|
||||
@@ -7,64 +7,88 @@ from odoo.tests import common
|
||||
|
||||
|
||||
class TestStockPickingValued(common.SavepointCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestStockPickingValued, cls).setUpClass()
|
||||
company = cls.env.user.company_id
|
||||
cls.tax = cls.env['account.tax'].create({
|
||||
'name': 'TAX 15%',
|
||||
'amount_type': 'percent',
|
||||
'type_tax_use': 'sale',
|
||||
'amount': 15.0,
|
||||
})
|
||||
cls.tax10 = cls.env['account.tax'].create({
|
||||
'name': 'TAX 10%',
|
||||
'amount_type': 'percent',
|
||||
'type_tax_use': 'sale',
|
||||
'amount': 10.0,
|
||||
})
|
||||
cls.product = cls.env['product.product'].create({
|
||||
'name': 'Test stuff',
|
||||
'list_price': 100.0,
|
||||
'taxes_id': [(6, 0, cls.tax.ids)],
|
||||
})
|
||||
cls.partner = cls.env['res.partner'].create({
|
||||
'name': 'Mr. Odoo',
|
||||
})
|
||||
cls.sale_order = cls.env['sale.order'].create({
|
||||
'partner_id': cls.partner.id,
|
||||
'order_line': [(0, 0, {
|
||||
'product_id': cls.product.id,
|
||||
'price_unit': 100,
|
||||
'product_uom_qty': 1,
|
||||
})],
|
||||
'company_id': company.id,
|
||||
})
|
||||
cls.sale_order2 = cls.env['sale.order'].create({
|
||||
'partner_id': cls.partner.id,
|
||||
'order_line': [
|
||||
(0, 0, {
|
||||
'product_id': cls.product.id,
|
||||
'price_unit': 100,
|
||||
'product_uom_qty': 1,
|
||||
}),
|
||||
(0, 0, {
|
||||
'product_id': cls.product.id,
|
||||
'price_unit': 100,
|
||||
'product_uom_qty': 1,
|
||||
}),
|
||||
(0, 0, {
|
||||
'product_id': cls.product.id,
|
||||
'price_unit': 100,
|
||||
'product_uom_qty': 1,
|
||||
'tax_id': [(6, 0, cls.tax10.ids)],
|
||||
}),
|
||||
],
|
||||
'company_id': company.id,
|
||||
})
|
||||
cls.sale_order.company_id.tax_calculation_rounding_method = (
|
||||
'round_per_line')
|
||||
cls.tax = cls.env["account.tax"].create(
|
||||
{
|
||||
"name": "TAX 15%",
|
||||
"amount_type": "percent",
|
||||
"type_tax_use": "sale",
|
||||
"amount": 15.0,
|
||||
}
|
||||
)
|
||||
cls.tax10 = cls.env["account.tax"].create(
|
||||
{
|
||||
"name": "TAX 10%",
|
||||
"amount_type": "percent",
|
||||
"type_tax_use": "sale",
|
||||
"amount": 10.0,
|
||||
}
|
||||
)
|
||||
cls.product = cls.env["product.product"].create(
|
||||
{
|
||||
"name": "Test stuff",
|
||||
"list_price": 100.0,
|
||||
"taxes_id": [(6, 0, cls.tax.ids)],
|
||||
}
|
||||
)
|
||||
cls.partner = cls.env["res.partner"].create({"name": "Mr. Odoo"})
|
||||
cls.sale_order = cls.env["sale.order"].create(
|
||||
{
|
||||
"partner_id": cls.partner.id,
|
||||
"order_line": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"product_id": cls.product.id,
|
||||
"price_unit": 100,
|
||||
"product_uom_qty": 1,
|
||||
},
|
||||
)
|
||||
],
|
||||
"company_id": company.id,
|
||||
}
|
||||
)
|
||||
cls.sale_order2 = cls.env["sale.order"].create(
|
||||
{
|
||||
"partner_id": cls.partner.id,
|
||||
"order_line": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"product_id": cls.product.id,
|
||||
"price_unit": 100,
|
||||
"product_uom_qty": 1,
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"product_id": cls.product.id,
|
||||
"price_unit": 100,
|
||||
"product_uom_qty": 1,
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"product_id": cls.product.id,
|
||||
"price_unit": 100,
|
||||
"product_uom_qty": 1,
|
||||
"tax_id": [(6, 0, cls.tax10.ids)],
|
||||
},
|
||||
),
|
||||
],
|
||||
"company_id": company.id,
|
||||
}
|
||||
)
|
||||
cls.sale_order.company_id.tax_calculation_rounding_method = "round_per_line"
|
||||
|
||||
def test_01_confirm_order(self):
|
||||
self.assertTrue(self.partner.valued_picking)
|
||||
@@ -87,8 +111,7 @@ class TestStockPickingValued(common.SavepointCase):
|
||||
self.assertEqual(picking.amount_total, 0.0)
|
||||
|
||||
def test_03_tax_rounding_method(self):
|
||||
self.sale_order.company_id.tax_calculation_rounding_method = (
|
||||
'round_globally')
|
||||
self.sale_order.company_id.tax_calculation_rounding_method = "round_globally"
|
||||
self.sale_order.action_confirm()
|
||||
self.assertTrue(len(self.sale_order.picking_ids))
|
||||
for picking in self.sale_order.picking_ids:
|
||||
@@ -98,8 +121,7 @@ class TestStockPickingValued(common.SavepointCase):
|
||||
self.assertEqual(picking.amount_total, 115.0)
|
||||
|
||||
def test_04_lines_distinct_tax(self):
|
||||
self.sale_order2.company_id.tax_calculation_rounding_method = (
|
||||
'round_globally')
|
||||
self.sale_order2.company_id.tax_calculation_rounding_method = "round_globally"
|
||||
self.sale_order2.action_confirm()
|
||||
self.assertTrue(len(self.sale_order2.picking_ids))
|
||||
for picking in self.sale_order2.picking_ids:
|
||||
|
||||
Reference in New Issue
Block a user