diff --git a/purchase_triple_discount/__manifest__.py b/purchase_triple_discount/__openerp__.py similarity index 78% rename from purchase_triple_discount/__manifest__.py rename to purchase_triple_discount/__openerp__.py index 7736ff5f17d..19385ea5727 100644 --- a/purchase_triple_discount/__manifest__.py +++ b/purchase_triple_discount/__openerp__.py @@ -2,10 +2,11 @@ # Copyright 2017 Tecnativa - David Vidal # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Account Invoice Triple Discount', - 'version': '10.0.1.1.0', + 'name': 'Purchase Order Triple Discount', + 'version': '8.0.1.0.0', 'category': 'Purchase Management', 'author': 'Tecnativa, ' + 'GRAP, ' 'Odoo Community Association (OCA)', 'website': 'https://tecnativa.com', 'license': 'AGPL-3', @@ -17,5 +18,8 @@ 'data': [ 'views/purchase_view.xml', ], + 'demo': [ + 'demo/purchase_order.xml', + ], 'installable': True, } diff --git a/purchase_triple_discount/demo/purchase_order.xml b/purchase_triple_discount/demo/purchase_order.xml new file mode 100644 index 00000000000..88032e934f3 --- /dev/null +++ b/purchase_triple_discount/demo/purchase_order.xml @@ -0,0 +1,38 @@ + + + + + + Purchase Order + + + + + + + Line 1 + + 1.0 + + + + 600 + 2018-01-19 + + + + Line 2 + + 10.0 + + + + 60 + 2018-01-19 + + + diff --git a/purchase_triple_discount/i18n/fr.po b/purchase_triple_discount/i18n/fr.po index c48818ccb1a..356ee7e1e68 100644 --- a/purchase_triple_discount/i18n/fr.po +++ b/purchase_triple_discount/i18n/fr.po @@ -7,25 +7,24 @@ # Quentin THEURET , 2017 msgid "" msgstr "" -"Project-Id-Version: Odoo Server 10.0\n" +"Project-Id-Version: Odoo Server 8.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-11-25 08:26+0000\n" -"PO-Revision-Date: 2017-11-25 08:26+0000\n" -"Last-Translator: Quentin THEURET , 2017\n" -"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"POT-Creation-Date: 2018-03-02 20:55+0000\n" +"PO-Revision-Date: 2018-03-02 20:55+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" -"Language: fr\n" -"Plural-Forms: nplurals=2; plural=(n > 1);\n" +"Plural-Forms: \n" #. module: purchase_triple_discount -#: model:ir.model.fields,field_description:purchase_triple_discount.field_purchase_order_line_discount2 +#: field:purchase.order.line,discount2:0 msgid "Disc. 2 (%)" msgstr "Rem. 2 (%)" #. module: purchase_triple_discount -#: model:ir.model.fields,field_description:purchase_triple_discount.field_purchase_order_line_discount3 +#: field:purchase.order.line,discount3:0 msgid "Disc. 3 (%)" msgstr "Rem. 3 (%)" @@ -44,7 +43,18 @@ msgstr "La remise 3 doit être inférieure à 100%." msgid "Invoice" msgstr "Facture" +#. module: purchase_triple_discount +#: model:ir.model,name:purchase_triple_discount.model_purchase_order +msgid "Purchase Order" +msgstr "Bon de commande" + #. module: purchase_triple_discount #: model:ir.model,name:purchase_triple_discount.model_purchase_order_line msgid "Purchase Order Line" msgstr "Ligne de commande d'achat" + +#. module: purchase_triple_discount +#: model:ir.model,name:purchase_triple_discount.model_stock_move +msgid "Stock Move" +msgstr "Mouvement de stock" + diff --git a/purchase_triple_discount/models/__init__.py b/purchase_triple_discount/models/__init__.py index c72976ae1ea..f9e757be450 100644 --- a/purchase_triple_discount/models/__init__.py +++ b/purchase_triple_discount/models/__init__.py @@ -2,3 +2,4 @@ from . import account_invoice from . import purchase_order +from . import stock_move diff --git a/purchase_triple_discount/models/account_invoice.py b/purchase_triple_discount/models/account_invoice.py index 18cb43c3a37..a06122e1a71 100644 --- a/purchase_triple_discount/models/account_invoice.py +++ b/purchase_triple_discount/models/account_invoice.py @@ -2,7 +2,7 @@ # Copyright 2017 Tecnativa - David Vidal # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models +from openerp import models class AccountInvoice(models.Model): diff --git a/purchase_triple_discount/models/purchase_order.py b/purchase_triple_discount/models/purchase_order.py index c2b2d363952..723538c76b2 100644 --- a/purchase_triple_discount/models/purchase_order.py +++ b/purchase_triple_discount/models/purchase_order.py @@ -2,13 +2,19 @@ # Copyright 2017 Tecnativa - David Vidal # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models -from odoo.addons import decimal_precision as dp +from openerp import api, fields, models +from openerp.addons import decimal_precision as dp class PurchaseOrderLine(models.Model): _inherit = "purchase.order.line" + @api.model + def _calc_line_base_price(self, line): + res = super(PurchaseOrderLine, self)._calc_line_base_price(line) + return res * (1 - line.discount2 / 100.0) *\ + (1 - line.discount3 / 100.0) + @api.depends('discount2', 'discount3') def _compute_amount(self): super(PurchaseOrderLine, self)._compute_amount() @@ -32,11 +38,35 @@ def _compute_amount(self): 'Discount 3 must be lower than 100%.'), ] - def _get_discounted_price_unit(self): - price_unit = super( - PurchaseOrderLine, self)._get_discounted_price_unit() - if self.discount2: - price_unit *= (1 - self.discount2 / 100.0) - if self.discount3: - price_unit *= (1 - self.discount3 / 100.0) - return price_unit + +class PurchaseOrder(models.Model): + _inherit = 'purchase.order' + + @api.model + def _prepare_inv_line(self, account_id, line): + res = super(PurchaseOrder, self)._prepare_inv_line(account_id, line) + res.update({ + 'discount2': line.discount2, + 'discount3': line.discount3, + }) + return res + + @api.model + def _prepare_order_line_move( + self, order, order_line, picking_id, group_id): + res = super(PurchaseOrder, self)._prepare_order_line_move( + order, order_line, picking_id, group_id) + for vals in res: + vals['price_unit'] = (vals.get('price_unit', 0.0) * + (1 - (order_line.discount2 / 100)) * + (1 - (order_line.discount3 / 100))) + return res + +# def _get_discounted_price_unit(self): +# price_unit = super( +# PurchaseOrderLine, self)._get_discounted_price_unit() +# if self.discount2: +# price_unit *= (1 - self.discount2 / 100.0) +# if self.discount3: +# price_unit *= (1 - self.discount3 / 100.0) +# return price_unit diff --git a/purchase_triple_discount/models/stock_move.py b/purchase_triple_discount/models/stock_move.py new file mode 100644 index 00000000000..1a27a68fbe6 --- /dev/null +++ b/purchase_triple_discount/models/stock_move.py @@ -0,0 +1,26 @@ +# coding: utf-8 +# Copyright (C) 2018 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, api + + +class StockMove(models.Model): + _inherit = "stock.move" + + @api.model + def _get_invoice_line_vals(self, move, partner, inv_type): + res = super(StockMove, self)._get_invoice_line_vals( + move, partner, inv_type) + order_line = False + if move.purchase_line_id: + order_line = move.purchase_line_id + elif move.origin_returned_move_id.purchase_line_id: + order_line = move.origin_returned_move_id.purchase_line_id + if order_line: + res.update({ + 'discount2': order_line.discount2, + 'discount3': order_line.discount3, + }) + return res diff --git a/purchase_triple_discount/tests/test_purchase_discount.py b/purchase_triple_discount/tests/test_purchase_discount.py index ac4f0b3e73d..112a78f9331 100644 --- a/purchase_triple_discount/tests/test_purchase_discount.py +++ b/purchase_triple_discount/tests/test_purchase_discount.py @@ -2,55 +2,19 @@ # Copyright 2017 Tecnativa - David Vidal # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo.tests import common +from openerp.tests import common class TestPurchaseOrder(common.SavepointCase): @classmethod - def setUpClass(cls): - super(TestPurchaseOrder, cls).setUpClass() - cls.partner = cls.env['res.partner'].create({ - 'name': 'Mr. Odoo', - }) - cls.product1 = cls.env['product.product'].create({ - 'name': 'Test Product 1', - 'purchase_method': 'purchase', - }) - cls.product2 = cls.env['product.product'].create({ - 'name': 'Test Product 2', - 'purchase_method': 'purchase', - }) - cls.tax = cls.env['account.tax'].create({ - 'name': 'TAX 15%', - 'amount_type': 'percent', - 'type_tax_use': 'purchase', - 'amount': 15.0, - }) - cls.order = cls.env['purchase.order'].create({ - 'partner_id': cls.partner.id - }) - po_line = cls.env['purchase.order.line'] - cls.po_line1 = po_line.create({ - 'order_id': cls.order.id, - 'product_id': cls.product1.id, - 'date_planned': '2018-01-19 00:00:00', - 'name': 'Line 1', - 'product_qty': 1.0, - 'product_uom': cls.product1.uom_id.id, - 'taxes_id': [(6, 0, [cls.tax.id])], - 'price_unit': 600.0, - }) - cls.po_line2 = po_line.create({ - 'order_id': cls.order.id, - 'product_id': cls.product2.id, - 'date_planned': '2018-01-19 00:00:00', - 'name': 'Line 2', - 'product_qty': 10.0, - 'product_uom': cls.product2.uom_id.id, - 'taxes_id': [(6, 0, [cls.tax.id])], - 'price_unit': 60.0, - }) + def setUpClass(self): + super(TestPurchaseOrder, self).setUpClass() + self.partner = self.env.ref('base.res_partner_1') + self.receivable_account = self.env.ref('account.a_recv') + self.order = self.env.ref('purchase_triple_discount.order') + self.po_line1 = self.env.ref('purchase_triple_discount.order_line1') + self.po_line2 = self.env.ref('purchase_triple_discount.order_line2') def test_01_purchase_order_classic_discount(self): """ Tests with single discount """ @@ -101,25 +65,18 @@ def test_03_purchase_order_complex_triple_discount(self): def test_04_purchase_order_triple_discount_invoicing(self): """ When a confirmed order is invoiced, the resultant invoice should inherit the discounts """ - self.po_line1.discount = 50.0 - self.po_line1.discount2 = 50.0 - self.po_line1.discount3 = 50.0 - self.po_line2.discount3 = 50.0 - self.order.button_confirm() - self.invoice = self.env['account.invoice'].create({ - 'partner_id': self.partner.id, - 'purchase_id': self.order.id, - 'account_id': self.partner.property_account_payable_id.id, - 'type': 'in_invoice', - }) - self.invoice.purchase_order_change() - self.invoice._onchange_invoice_line_ids() + self.po_line1.discount = 10.0 + self.po_line1.discount2 = 20.0 + self.po_line1.discount3 = 30.0 + self.po_line2.discount3 = 40.0 + self.order.signal_workflow('purchase_confirm') + self.invoice = self.order.invoice_ids[0] self.assertEqual(self.po_line1.discount, - self.invoice.invoice_line_ids[0].discount) + self.invoice.invoice_line[0].discount) self.assertEqual(self.po_line1.discount2, - self.invoice.invoice_line_ids[0].discount2) + self.invoice.invoice_line[0].discount2) self.assertEqual(self.po_line1.discount3, - self.invoice.invoice_line_ids[0].discount3) + self.invoice.invoice_line[0].discount3) self.assertEqual(self.po_line2.discount3, - self.invoice.invoice_line_ids[1].discount3) + self.invoice.invoice_line[1].discount3) self.assertEqual(self.order.amount_total, self.invoice.amount_total) diff --git a/purchase_triple_discount/views/purchase_view.xml b/purchase_triple_discount/views/purchase_view.xml index 58b5a089794..99a05e4e0d4 100644 --- a/purchase_triple_discount/views/purchase_view.xml +++ b/purchase_triple_discount/views/purchase_view.xml @@ -1,22 +1,17 @@ - + purchase.order.triple.discount.form purchase.order - + - - - - - +