Skip to content

Commit

Permalink
[MIG] purchase_force_invoiced: Migration to 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kongrattapong authored and Reyes4711-S73 committed Sep 20, 2021
1 parent 125fda0 commit 537f08d
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 88 deletions.
11 changes: 6 additions & 5 deletions purchase_force_invoiced/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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.

Expand All @@ -76,6 +76,7 @@ Contributors
~~~~~~~~~~~~

* Jordi Ballester <[email protected]>
* Rattapong Chokmasermkul <[email protected]>

Maintainers
~~~~~~~~~~~
Expand All @@ -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.
2 changes: 2 additions & 0 deletions purchase_force_invoiced/__init__.py
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
6 changes: 3 additions & 3 deletions purchase_force_invoiced/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# 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)

{
"name": "Purchase Force Invoiced",
"summary": "Allows to force the billing status of the purchase order to "
'"Invoiced"',
"version": "12.0.1.0.0",
"author": "Eficent," "Odoo Community Association (OCA)",
"version": "13.0.1.0.0",
"author": "Forgeflow, Odoo Community Association (OCA)",
"category": "Purchase Management",
"license": "AGPL-3",
"website": "https://github.com/OCA/purchase-workflow",
Expand Down
5 changes: 3 additions & 2 deletions purchase_force_invoiced/model/__init__.py
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
19 changes: 0 additions & 19 deletions purchase_force_invoiced/model/account_invoice.py

This file was deleted.

37 changes: 37 additions & 0 deletions purchase_force_invoiced/model/purchase.py
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
26 changes: 0 additions & 26 deletions purchase_force_invoiced/model/purchase_order.py

This file was deleted.

1 change: 1 addition & 0 deletions purchase_force_invoiced/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* Jordi Ballester <[email protected]>
* Rattapong Chokmasermkul <[email protected]>
7 changes: 4 additions & 3 deletions purchase_force_invoiced/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Purchase Force Invoiced</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/12.0/purchase_force_invoiced"><img alt="OCA/purchase-workflow" src="https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/purchase-workflow-12-0/purchase-workflow-12-0-purchase_force_invoiced"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/142/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/13.0-mig-purchase_force_invoiced/purchase_force_invoiced"><img alt="OCA/purchase-workflow" src="https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github" /></a> <a class="reference external" href="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"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/142/13.0-mig-purchase_force_invoiced"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module adds the possibility for users to force the invoice status of the
purchase orders to ‘No Bill to Receive’, even when not all the
quantities, ordered or delivered, have been invoiced.</p>
Expand Down Expand Up @@ -409,7 +409,7 @@ <h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/purchase-workflow/issues">GitHub Issues</a>.
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
<a class="reference external" href="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</a>.</p>
<a class="reference external" href="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**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -424,6 +424,7 @@ <h2><a class="toc-backref" href="#id4">Authors</a></h2>
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<ul class="simple">
<li>Jordi Ballester &lt;<a class="reference external" href="mailto:jordi.ballester&#64;eficent.com">jordi.ballester&#64;eficent.com</a>&gt;</li>
<li>Rattapong Chokmasermkul &lt;<a class="reference external" href="mailto:rattapongc&#64;ecosoft.co.th">rattapongc&#64;ecosoft.co.th</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -433,7 +434,7 @@ <h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/12.0/purchase_force_invoiced">OCA/purchase-workflow</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/13.0-mig-purchase_force_invoiced/purchase_force_invoiced">OCA/purchase-workflow</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions purchase_force_invoiced/tests/__init__.py
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
61 changes: 40 additions & 21 deletions purchase_force_invoiced/tests/test_purchase_force_invoiced.py
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
Expand All @@ -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()
Expand All @@ -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):
Expand All @@ -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(
Expand Down Expand Up @@ -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"
)
Expand All @@ -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)
15 changes: 6 additions & 9 deletions purchase_force_invoiced/view/purchase_view.xml
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>

0 comments on commit 537f08d

Please sign in to comment.