forked from OCA/purchase-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] purchase_force_invoiced: Migration to 13.0
- Loading branch information
1 parent
125fda0
commit 537f08d
Showing
12 changed files
with
104 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,13 @@ Purchase Force Invoiced | |
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github | ||
:target: https://github.com/OCA/purchase-workflow/tree/12.0/purchase_force_invoiced | ||
:target: https://github.com/OCA/purchase-workflow/tree/13.0-mig-purchase_force_invoiced/purchase_force_invoiced | ||
:alt: OCA/purchase-workflow | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/purchase-workflow-12-0/purchase-workflow-12-0-purchase_force_invoiced | ||
:target: https://translation.odoo-community.org/projects/purchase-workflow-13-0-mig-purchase_force_invoiced/purchase-workflow-13-0-mig-purchase_force_invoiced-purchase_force_invoiced | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/142/12.0 | ||
:target: https://runbot.odoo-community.org/runbot/142/13.0-mig-purchase_force_invoiced | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
@@ -60,7 +60,7 @@ Bug Tracker | |
Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/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 <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_force_invoiced%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_force_invoiced%0Aversion:%2013.0-mig-purchase_force_invoiced%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
|
@@ -76,6 +76,7 @@ Contributors | |
~~~~~~~~~~~~ | ||
|
||
* Jordi Ballester <[email protected]> | ||
* Rattapong Chokmasermkul <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
@@ -90,6 +91,6 @@ 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. | ||
|
||
This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/12.0/purchase_force_invoiced>`_ project on GitHub. | ||
This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/13.0-mig-purchase_force_invoiced/purchase_force_invoiced>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) | ||
|
||
from . import model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from . import purchase_order | ||
from . import account_invoice | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) | ||
|
||
from . import purchase |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class PurchaseOrder(models.Model): | ||
_inherit = "purchase.order" | ||
|
||
force_invoiced = fields.Boolean( | ||
string="Force invoiced", | ||
readonly=True, | ||
states={"done": [("readonly", False)]}, | ||
copy=False, | ||
help="When you set this field, the purchase order will be " | ||
"considered as fully billed, even when there may be ordered " | ||
"or delivered quantities pending to bill.", | ||
) | ||
|
||
@api.depends("force_invoiced") | ||
def _get_invoiced(self): | ||
super(PurchaseOrder, self)._get_invoiced() | ||
for order in self.filtered( | ||
lambda po: po.force_invoiced and po.invoice_status == "to invoice" | ||
): | ||
order.invoice_status = "invoiced" | ||
|
||
|
||
class PurchaseOrderLine(models.Model): | ||
_inherit = "purchase.order.line" | ||
|
||
def _prepare_account_move_line(self, line): | ||
res = super(PurchaseOrderLine, self)._prepare_account_move_line(line) | ||
if res.get("purchase_line_id", False): | ||
pol = self.browse(res["purchase_line_id"]) | ||
if pol.order_id.force_invoiced: | ||
res["quantity"] = 0.0 | ||
return res |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
* Jordi Ballester <[email protected]> | ||
* Rattapong Chokmasermkul <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) | ||
|
||
from . import test_purchase_force_invoiced |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Copyright 2019 Eficent Business and IT Consulting Services S.L. | ||
# Copyright 2019 Aleph Objects, Inc. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) | ||
|
||
from odoo import fields | ||
from odoo.tests.common import TransactionCase | ||
|
@@ -11,8 +11,18 @@ def setUp(self): | |
super(TestPurchaseForceInvoiced, self).setUp() | ||
self.purchase_order_model = self.env["purchase.order"] | ||
self.purchase_order_line_model = self.env["purchase.order.line"] | ||
self.account_invoice_model = self.env["account.invoice"] | ||
self.account_invoice_line = self.env["account.invoice.line"] | ||
self.account_invoice_model = self.env["account.move"] | ||
self.account_invoice_line = self.env["account.move.line"] | ||
self.invoice_account = self.env["account.account"].search( | ||
[ | ||
( | ||
"user_type_id", | ||
"=", | ||
self.env.ref("account.data_account_type_revenue").id, | ||
) | ||
], | ||
limit=1, | ||
) | ||
|
||
# Data | ||
product_ctg = self._create_product_category() | ||
|
@@ -23,12 +33,7 @@ def setUp(self): | |
def _create_supplier(self, name): | ||
"""Create a Partner.""" | ||
return self.env["res.partner"].create( | ||
{ | ||
"name": name, | ||
"email": "[email protected]", | ||
"supplier": True, | ||
"phone": 123456, | ||
} | ||
{"name": name, "email": "[email protected]", "phone": 123456} | ||
) | ||
|
||
def _create_product_category(self): | ||
|
@@ -47,19 +52,31 @@ def _create_product(self, name, product_ctg): | |
return product | ||
|
||
def _create_invoice_from_purchase(self, purchase): | ||
|
||
invoice = self.account_invoice_model.create( | ||
{ | ||
"partner_id": purchase.partner_id.id, | ||
"purchase_id": purchase.id, | ||
"account_id": purchase.partner_id.property_account_payable_id.id, | ||
"type": "in_invoice", | ||
} | ||
{"partner_id": purchase.partner_id.id, "type": "in_invoice"} | ||
) | ||
invoice.purchase_order_change() | ||
invoice.write({"purchase_id": purchase.id}) | ||
invoice._onchange_purchase_auto_complete() | ||
|
||
return invoice | ||
|
||
def create_invoice_line(self, line, invoice): | ||
vals = [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"name": line.name, | ||
"product_id": line.product_id.id, | ||
"quantity": line.qty_received - line.qty_invoiced, | ||
"price_unit": line.price_unit, | ||
"account_id": self.invoice_account.id, | ||
"purchase_line_id": line.id, | ||
}, | ||
) | ||
] | ||
return invoice.update({"invoice_line_ids": vals}) | ||
|
||
def test_purchase_order(self): | ||
po = self.purchase_order_model.create({"partner_id": self.customer.id}) | ||
pol1 = self.purchase_order_line_model.create( | ||
|
@@ -95,14 +112,16 @@ def test_purchase_order(self): | |
po.invoice_status, "to invoice", "The invoice status should be To Invoice" | ||
) | ||
|
||
self._create_invoice_from_purchase(po) | ||
invoice = self._create_invoice_from_purchase(po) | ||
self.create_invoice_line(pol1, invoice) | ||
self.create_invoice_line(pol2, invoice) | ||
self.assertEquals( | ||
po.invoice_status, "invoiced", "The invoice status should be Invoiced" | ||
) | ||
|
||
# Reduce the invoiced qty | ||
for line in pol2.invoice_lines: | ||
line.quantity = 1 | ||
line.with_context(check_move_validity=False).unlink() | ||
self.assertEquals( | ||
po.invoice_status, "to invoice", "The invoice status should be To Invoice" | ||
) | ||
|
@@ -120,6 +139,6 @@ def test_purchase_order(self): | |
self.assertEquals( | ||
po.invoice_status, "to invoice", "The invoice status should be To Invoice" | ||
) | ||
invoice = self._create_invoice_from_purchase(po) | ||
self.create_invoice_line(pol2, invoice) | ||
invoice_qty = sum(invoice.mapped("invoice_line_ids.quantity")) | ||
self.assertEqual(invoice_qty, 1.0) | ||
self.assertEqual(invoice_qty, 2.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- Copyright 2019 Eficent Business and IT Consulting Services S.L. | ||
Copyright 2019 Aleph Objects, Inc. | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
|
||
<record id="purchase_order_form" model="ir.ui.view"> | ||
<field name="name">purchase.order.form</field> | ||
<field name="model">purchase.order</field> | ||
<field name="inherit_id" ref="purchase.purchase_order_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="invoice_status" position="after"> | ||
<field name="force_invoiced" | ||
groups="purchase.group_purchase_manager"/> | ||
</field> | ||
<field name="inherit_id" ref="purchase.purchase_order_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="invoice_status" position="after"> | ||
<field name="force_invoiced" groups="purchase.group_purchase_manager" /> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |