From 98e3a6c39481f454f43b632ada1af5f3ad77f3e0 Mon Sep 17 00:00:00 2001 From: "Luis M. Ontalba" Date: Mon, 9 Apr 2018 15:21:35 +0200 Subject: [PATCH 01/20] [11.0][MIG] stock_valued_picking_report --- stock_picking_report_valued/README.rst | 80 +++++++++++ stock_picking_report_valued/__init__.py | 3 + stock_picking_report_valued/__manifest__.py | 26 ++++ stock_picking_report_valued/i18n/es.po | 134 ++++++++++++++++++ stock_picking_report_valued/i18n/hr.po | 127 +++++++++++++++++ .../models/__init__.py | 4 + .../models/res_partner.py | 15 ++ .../models/stock_move_line.py | 61 ++++++++ .../models/stock_picking.py | 40 ++++++ .../report/stock_picking_report_valued.xml | 65 +++++++++ stock_picking_report_valued/tests/__init__.py | 2 + .../tests/test_stock_picking_valued.py | 64 +++++++++ .../views/res_partner_view.xml | 16 +++ 13 files changed, 637 insertions(+) create mode 100644 stock_picking_report_valued/README.rst create mode 100644 stock_picking_report_valued/__init__.py create mode 100644 stock_picking_report_valued/__manifest__.py create mode 100644 stock_picking_report_valued/i18n/es.po create mode 100644 stock_picking_report_valued/i18n/hr.po create mode 100644 stock_picking_report_valued/models/__init__.py create mode 100644 stock_picking_report_valued/models/res_partner.py create mode 100644 stock_picking_report_valued/models/stock_move_line.py create mode 100644 stock_picking_report_valued/models/stock_picking.py create mode 100644 stock_picking_report_valued/report/stock_picking_report_valued.xml create mode 100644 stock_picking_report_valued/tests/__init__.py create mode 100644 stock_picking_report_valued/tests/test_stock_picking_valued.py create mode 100644 stock_picking_report_valued/views/res_partner_view.xml diff --git a/stock_picking_report_valued/README.rst b/stock_picking_report_valued/README.rst new file mode 100644 index 0000000..99d4caa --- /dev/null +++ b/stock_picking_report_valued/README.rst @@ -0,0 +1,80 @@ +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +=========================== +Stock Picking Report Valued +=========================== + +Add amount information to Delivery Slip report. +You can select at partner level if picking list report must be valued or not. +If the picking is done it's valued with quantity done, otherwise the picking +is valued with reserved quantity. + +Configuration +============= + +#. Go to *Customers > (select one of your choice) > Sales & Purchases*. +#. Set *Valued picking* field on. + +Usage +===== + +To get the stock picking valued report: + +#. Create a Sale Order with stockable products a *Valued picking* able + customer. +#. Confirm the Sale Order. +#. Click on *Deliveries* stat button. +#. Go to *Print > Delivery Slip*. + + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/151/11.0 + +Known issues / Roadmap +====================== + +* If the picking is not reserved, values aren't computed. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Pedro M. Baeza +* Antonio Espinosa +* Oihane Crucelaegui +* Carlos Dauden +* David Vidal +* Luis M. Ontalba + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/stock_picking_report_valued/__init__.py b/stock_picking_report_valued/__init__.py new file mode 100644 index 0000000..cde864b --- /dev/null +++ b/stock_picking_report_valued/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models diff --git a/stock_picking_report_valued/__manifest__.py b/stock_picking_report_valued/__manifest__.py new file mode 100644 index 0000000..1ab8755 --- /dev/null +++ b/stock_picking_report_valued/__manifest__.py @@ -0,0 +1,26 @@ +# Copyright 2014 Pedro M. Baeza - Tecnativa +# Copyright 2015 Antonio Espinosa - Tecnativa +# Copyright 2016 Carlos Dauden - Tecnativa +# Copyright 2017 David Vidal - Tecnativa +# Copyright 2017 Luis M. Ontalba - Tecnativa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Valued Picking Report", + "summary": "Adding Valued Picking on Delivery Slip report", + "version": "11.0.1.0.0", + "author": "Tecnativa, " + "Odoo Community Association (OCA)", + "website": "https://www.tecnativa.com", + "category": "Warehouse Management", + "license": "AGPL-3", + "depends": [ + "sale_management", + "stock", + ], + "data": [ + 'views/res_partner_view.xml', + 'report/stock_picking_report_valued.xml', + ], + "installable": True, +} diff --git a/stock_picking_report_valued/i18n/es.po b/stock_picking_report_valued/i18n/es.po new file mode 100644 index 0000000..48bb44f --- /dev/null +++ b/stock_picking_report_valued/i18n/es.po @@ -0,0 +1,134 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_picking_report_valued +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-08-21 08:13+0000\n" +"PO-Revision-Date: 2017-08-21 10:13+0200\n" +"Last-Translator: Carlos Dauden \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"Language: es\n" +"X-Generator: Poedit 1.8.7.1\n" + +#. module: stock_picking_report_valued +#: model:ir.ui.view,arch_db:stock_picking_report_valued.valued_report_picking +msgid "Discount" +msgstr "Dto" + +#. module: stock_picking_report_valued +#: model:ir.ui.view,arch_db:stock_picking_report_valued.valued_report_picking +msgid "Subtotal" +msgstr "Subtotal" + +#. module: stock_picking_report_valued +#: model:ir.ui.view,arch_db:stock_picking_report_valued.valued_report_picking +msgid "Taxes" +msgstr "Impuestos" + +#. module: stock_picking_report_valued +#: model:ir.ui.view,arch_db:stock_picking_report_valued.valued_report_picking +msgid "Total" +msgstr "Total" + +#. module: stock_picking_report_valued +#: model:ir.ui.view,arch_db:stock_picking_report_valued.valued_report_picking +msgid "Unit Price" +msgstr "Precio Unidad" + +#. module: stock_picking_report_valued +#: model:ir.ui.view,arch_db:stock_picking_report_valued.valued_report_picking +msgid "Untaxed Amount" +msgstr "Base imponible" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_currency_id +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_picking_currency_id +msgid "Currency" +msgstr "Moneda" + +#. module: stock_picking_report_valued +#: model:ir.model,name:stock_picking_report_valued.model_stock_pack_operation +msgid "Packing Operation" +msgstr "Operación de empaquetado" + +#. module: stock_picking_report_valued +#: model:ir.model,name:stock_picking_report_valued.model_res_partner +msgid "Partner" +msgstr "Empresa" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_sale_price_subtotal +msgid "Price subtotal" +msgstr "Subtotal" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_sale_line +msgid "Related order line" +msgstr "Línea de pedido relacionada" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_sale_discount +msgid "Sale discount (%)" +msgstr "Descuento venta (%)" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_sale_price_unit +msgid "Sale price unit" +msgstr "Precio venta" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_sale_tax_description +msgid "Tax Description" +msgstr "Descripción de impuesto" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_sale_price_tax +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_sale_tax_id +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_picking_amount_tax +msgid "Taxes" +msgstr "Impuestos" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_sale_price_total +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_picking_amount_total +msgid "Total" +msgstr "Total" + +#. module: stock_picking_report_valued +#: model:ir.model,name:stock_picking_report_valued.model_stock_picking +msgid "Transfer" +msgstr "Transferir" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_picking_amount_untaxed +msgid "Untaxed Amount" +msgstr "Base imponible" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_res_partner_valued_picking +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_picking_valued +msgid "Valued picking" +msgstr "Albarán valorado" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_picking_website_message_ids +msgid "Website Messages" +msgstr "Mensajes del sitio web" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,help:stock_picking_report_valued.field_stock_picking_website_message_ids +msgid "Website communication history" +msgstr "Historial de comunicaciones del sitio web" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,help:stock_picking_report_valued.field_res_partner_valued_picking +#: model:ir.model.fields,help:stock_picking_report_valued.field_stock_picking_valued +msgid "You can select which partners have valued pickings" +msgstr "Puede seleccionar qué empresas tienen albarán valorado" diff --git a/stock_picking_report_valued/i18n/hr.po b/stock_picking_report_valued/i18n/hr.po new file mode 100644 index 0000000..1da143e --- /dev/null +++ b/stock_picking_report_valued/i18n/hr.po @@ -0,0 +1,127 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_picking_report_valued +# +# Translators: +# Bole , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-01 02:22+0000\n" +"PO-Revision-Date: 2017-12-01 02:22+0000\n" +"Last-Translator: Bole , 2018\n" +"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: hr\n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" + +#. module: stock_picking_report_valued +#: model:ir.ui.view,arch_db:stock_picking_report_valued.valued_report_picking +msgid "Discount" +msgstr "Popust" + +#. module: stock_picking_report_valued +#: model:ir.ui.view,arch_db:stock_picking_report_valued.valued_report_picking +msgid "Subtotal" +msgstr "Subtotal" + +#. module: stock_picking_report_valued +#: model:ir.ui.view,arch_db:stock_picking_report_valued.valued_report_picking +msgid "Taxes" +msgstr "Porezi" + +#. module: stock_picking_report_valued +#: model:ir.ui.view,arch_db:stock_picking_report_valued.valued_report_picking +msgid "Total" +msgstr "Total" + +#. module: stock_picking_report_valued +#: model:ir.ui.view,arch_db:stock_picking_report_valued.valued_report_picking +msgid "Unit Price" +msgstr "Jed.cijena" + +#. module: stock_picking_report_valued +#: model:ir.ui.view,arch_db:stock_picking_report_valued.valued_report_picking +msgid "Untaxed Amount" +msgstr "Bez poreza" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_currency_id +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_picking_currency_id +msgid "Currency" +msgstr "Valuta" + +#. module: stock_picking_report_valued +#: model:ir.model,name:stock_picking_report_valued.model_stock_pack_operation +msgid "Packing Operation" +msgstr "Operacija pakiranja" + +#. module: stock_picking_report_valued +#: model:ir.model,name:stock_picking_report_valued.model_res_partner +msgid "Partner" +msgstr "Partner" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_sale_price_subtotal +msgid "Price subtotal" +msgstr "" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_sale_line +msgid "Related order line" +msgstr "Povezana stavka ponude" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_sale_discount +msgid "Sale discount (%)" +msgstr "Popust prodaje (%)" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_sale_price_unit +msgid "Sale price unit" +msgstr "Prodajna cijena" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_sale_tax_description +msgid "Tax Description" +msgstr "Opis poreza" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_sale_price_tax +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_sale_tax_id +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_picking_amount_tax +msgid "Taxes" +msgstr "Porezi" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_pack_operation_sale_price_total +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_picking_amount_total +msgid "Total" +msgstr "Ukupno" + +#. module: stock_picking_report_valued +#: model:ir.model,name:stock_picking_report_valued.model_stock_picking +msgid "Transfer" +msgstr "Transfer" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_picking_amount_untaxed +msgid "Untaxed Amount" +msgstr "Iznos bez poreza" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_res_partner_valued_picking +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_res_users_valued_picking +#: model:ir.model.fields,field_description:stock_picking_report_valued.field_stock_picking_valued +msgid "Valued picking" +msgstr "" + +#. module: stock_picking_report_valued +#: model:ir.model.fields,help:stock_picking_report_valued.field_res_partner_valued_picking +#: model:ir.model.fields,help:stock_picking_report_valued.field_res_users_valued_picking +#: model:ir.model.fields,help:stock_picking_report_valued.field_stock_picking_valued +msgid "You can select which partners have valued pickings" +msgstr "" diff --git a/stock_picking_report_valued/models/__init__.py b/stock_picking_report_valued/models/__init__.py new file mode 100644 index 0000000..87bf9bb --- /dev/null +++ b/stock_picking_report_valued/models/__init__.py @@ -0,0 +1,4 @@ + +from . import res_partner +from . import stock_move_line +from . import stock_picking diff --git a/stock_picking_report_valued/models/res_partner.py b/stock_picking_report_valued/models/res_partner.py new file mode 100644 index 0000000..6002cfe --- /dev/null +++ b/stock_picking_report_valued/models/res_partner.py @@ -0,0 +1,15 @@ +# Copyright 2014 Pedro M. Baeza - Tecnativa +# Copyright 2015 Antonio Espinosa - Tecnativa +# Copyright 2016 Carlos Dauden - Tecnativa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + valued_picking = fields.Boolean( + default=True, + help='You can select which partners have valued pickings', + ) diff --git a/stock_picking_report_valued/models/stock_move_line.py b/stock_picking_report_valued/models/stock_move_line.py new file mode 100644 index 0000000..9a22306 --- /dev/null +++ b/stock_picking_report_valued/models/stock_move_line.py @@ -0,0 +1,61 @@ +# Copyright 2014 Pedro M. Baeza - Tecnativa +# Copyright 2015 Antonio Espinosa - Tecnativa +# Copyright 2016 Carlos Dauden - Tecnativa +# Copyright 2018 Luis M. Ontalba - Tecnativa +# 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" + + 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') + sale_price_unit = fields.Float( + related='sale_line.price_unit', readonly=True, + string="Sale price unit") + sale_discount = fields.Float( + related='sale_line.discount', readonly=True, + string="Sale discount (%)") + sale_price_subtotal = fields.Monetary( + compute='_compute_amount', + string="Price subtotal") + sale_price_tax = fields.Float( + compute='_compute_amount', + string='Taxes') + + @api.multi + @api.depends('sale_line.tax_id') + def _compute_sale_tax_description(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, + partner=line.sale_line.order_id.partner_shipping_id) + line.update({ + 'sale_price_tax': sum( + t.get('amount', 0.0) for t in taxes.get('taxes', [])), + 'sale_price_subtotal': taxes['total_excluded'], + }) diff --git a/stock_picking_report_valued/models/stock_picking.py b/stock_picking_report_valued/models/stock_picking.py new file mode 100644 index 0000000..ed5afd2 --- /dev/null +++ b/stock_picking_report_valued/models/stock_picking.py @@ -0,0 +1,40 @@ +# Copyright 2014 Pedro M. Baeza - Tecnativa +# Copyright 2015 Antonio Espinosa - Tecnativa +# Copyright 2016 Carlos Dauden - Tecnativa +# Copyright 2016 Luis M. Ontalba - Tecnativa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + valued = fields.Boolean( + related='partner_id.valued_picking', readonly=True, + ) + currency_id = fields.Many2one( + related='sale_id.currency_id', readonly=True, + string='Currency') + amount_untaxed = fields.Monetary( + compute='_compute_amount_all', + string='Untaxed Amount') + amount_tax = fields.Monetary( + compute='_compute_amount_all', + string='Taxes') + amount_total = fields.Monetary( + compute='_compute_amount_all', + string='Total') + + @api.multi + def _compute_amount_all(self): + for pick in self: + amount_untaxed = sum(pick.move_line_ids.mapped( + 'sale_price_subtotal')) + amount_tax = sum(pick.move_line_ids.mapped( + 'sale_price_tax')) + pick.update({ + 'amount_untaxed': amount_untaxed, + 'amount_tax': amount_tax, + 'amount_total': amount_untaxed + amount_tax, + }) diff --git a/stock_picking_report_valued/report/stock_picking_report_valued.xml b/stock_picking_report_valued/report/stock_picking_report_valued.xml new file mode 100644 index 0000000..cb6082e --- /dev/null +++ b/stock_picking_report_valued/report/stock_picking_report_valued.xml @@ -0,0 +1,65 @@ + + + + + + diff --git a/stock_picking_report_valued/tests/__init__.py b/stock_picking_report_valued/tests/__init__.py new file mode 100644 index 0000000..4fba0fd --- /dev/null +++ b/stock_picking_report_valued/tests/__init__.py @@ -0,0 +1,2 @@ + +from . import test_stock_picking_valued diff --git a/stock_picking_report_valued/tests/test_stock_picking_valued.py b/stock_picking_report_valued/tests/test_stock_picking_valued.py new file mode 100644 index 0000000..77670cd --- /dev/null +++ b/stock_picking_report_valued/tests/test_stock_picking_valued.py @@ -0,0 +1,64 @@ +# Copyright 2017 Tecnativa - David Vidal +# Copyright 2017 Tecnativa - Luis M. Ontalba +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests import common + + +class TestStockPickingValued(common.SavepointCase): + + @classmethod + def setUpClass(cls): + super(TestStockPickingValued, cls).setUpClass() + cls.tax = cls.env['account.tax'].create({ + 'name': 'TAX 15%', + 'amount_type': 'percent', + 'type_tax_use': 'sale', + 'amount': 15.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})], + 'company_id': cls.env.user.company_id.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) + self.sale_order.action_confirm() + self.assertTrue(len(self.sale_order.picking_ids)) + for picking in self.sale_order.picking_ids: + picking.action_assign() + self.assertEqual(picking.amount_untaxed, 100.0) + self.assertEqual(picking.amount_tax, 15.0) + self.assertEqual(picking.amount_total, 115.0) + + def test_02_confirm_order(self): + """ Valued picking isn't computed if not reserved """ + self.sale_order.action_confirm() + for picking in self.sale_order.picking_ids: + picking.action_assign() + picking.do_unreserve() + self.assertEqual(picking.amount_untaxed, 0.0) + self.assertEqual(picking.amount_tax, 0.0) + 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.action_confirm() + self.assertTrue(len(self.sale_order.picking_ids)) + for picking in self.sale_order.picking_ids: + picking.action_assign() + self.assertEqual(picking.amount_untaxed, 100.0) + self.assertEqual(picking.amount_tax, 15.0) + self.assertEqual(picking.amount_total, 115.0) diff --git a/stock_picking_report_valued/views/res_partner_view.xml b/stock_picking_report_valued/views/res_partner_view.xml new file mode 100644 index 0000000..e331eaf --- /dev/null +++ b/stock_picking_report_valued/views/res_partner_view.xml @@ -0,0 +1,16 @@ + + + + + Partner view (Valued picking) + res.partner + + + + + + + + + From 25c8a36a0bc390aba18c9eda7ae2ee5093b81d31 Mon Sep 17 00:00:00 2001 From: Carlos Dauden Date: Tue, 10 Jul 2018 19:47:14 +0200 Subject: [PATCH 02/20] [IMP] stock_picking_report_valued: Improve code --- stock_picking_report_valued/__init__.py | 2 - .../models/stock_move_line.py | 71 ++++++++++--------- .../views/res_partner_view.xml | 2 +- 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/stock_picking_report_valued/__init__.py b/stock_picking_report_valued/__init__.py index cde864b..0650744 100644 --- a/stock_picking_report_valued/__init__.py +++ b/stock_picking_report_valued/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - from . import models diff --git a/stock_picking_report_valued/models/stock_move_line.py b/stock_picking_report_valued/models/stock_move_line.py index 9a22306..5679c5a 100644 --- a/stock_picking_report_valued/models/stock_move_line.py +++ b/stock_picking_report_valued/models/stock_move_line.py @@ -1,61 +1,62 @@ # Copyright 2014 Pedro M. Baeza - Tecnativa # Copyright 2015 Antonio Espinosa - Tecnativa -# Copyright 2016 Carlos Dauden - Tecnativa # Copyright 2018 Luis M. Ontalba - Tecnativa +# Copyright 2016-2018 Carlos Dauden - Tecnativa # 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'], }) diff --git a/stock_picking_report_valued/views/res_partner_view.xml b/stock_picking_report_valued/views/res_partner_view.xml index e331eaf..c17da3a 100644 --- a/stock_picking_report_valued/views/res_partner_view.xml +++ b/stock_picking_report_valued/views/res_partner_view.xml @@ -1,4 +1,4 @@ - + From 03cc171eb2a23c67fa17781581993f0f1e45dc1f Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Fri, 13 Jul 2018 02:02:45 +0200 Subject: [PATCH 03/20] [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')) From 56003b493d26c89f80aca60300cce25c2a937db9 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 26 Jul 2018 10:28:11 +0200 Subject: [PATCH 04/20] [FIX] stock_picking_report_valued: core view change - This commit https://github.com/odoo/odoo/commit/41bea4125cc898bbcc7ca14fa5be112512c67d8e breaked the inheritance. --- .../report/stock_picking_report_valued.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stock_picking_report_valued/report/stock_picking_report_valued.xml b/stock_picking_report_valued/report/stock_picking_report_valued.xml index cb6082e..449eb03 100644 --- a/stock_picking_report_valued/report/stock_picking_report_valued.xml +++ b/stock_picking_report_valued/report/stock_picking_report_valued.xml @@ -2,7 +2,7 @@