Skip to content

Commit

Permalink
[MIG] pos_session_pay_invoice: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-lopez-tecnativa committed Jul 19, 2024
1 parent a7f9b43 commit 3c68f22
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 120 deletions.
13 changes: 8 additions & 5 deletions pos_session_pay_invoice/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ POS Session Pay invoice
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github
:target: https://github.com/OCA/pos/tree/14.0/pos_session_pay_invoice
:target: https://github.com/OCA/pos/tree/16.0/pos_session_pay_invoice
:alt: OCA/pos
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/pos-14-0/pos-14-0-pos_session_pay_invoice
:target: https://translation.odoo-community.org/projects/pos-16-0/pos-16-0-pos_session_pay_invoice
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/pos&target_branch=14.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/pos&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -68,7 +68,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/pos/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/pos/issues/new?body=module:%20pos_session_pay_invoice%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/pos/issues/new?body=module:%20pos_session_pay_invoice%0Aversion:%2016.0%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 @@ -85,6 +85,9 @@ Contributors

* Enric Tobella <[email protected]>
* Jordi Ballester <[email protected]>
* Tecnativa (https://www.tecnativa.com):

* Carlos Lopez

Maintainers
~~~~~~~~~~~
Expand All @@ -99,6 +102,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/pos <https://github.com/OCA/pos/tree/14.0/pos_session_pay_invoice>`_ project on GitHub.
This module is part of the `OCA/pos <https://github.com/OCA/pos/tree/16.0/pos_session_pay_invoice>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 2 additions & 2 deletions pos_session_pay_invoice/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "POS Session Pay invoice",
"version": "14.0.1.1.0",
"version": "16.0.1.0.0",
"category": "Point Of Sale",
"author": "Creu Blanca, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/pos",
Expand All @@ -14,7 +14,7 @@
"security/ir.model.access.csv",
"wizard/pos_box_cash_invoice_out.xml",
"wizard/pos_box_cash_invoice_in.xml",
"wizard/cash_invoice_in.xml",
"wizard/cash_pay_invoice.xml",
"views/pos_session.xml",
],
}
1 change: 1 addition & 0 deletions pos_session_pay_invoice/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import pos_order
from . import pos_session
17 changes: 17 additions & 0 deletions pos_session_pay_invoice/models/pos_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from odoo import models


class PosSession(models.Model):
_inherit = "pos.session"

def button_show_wizard_pay_invoice(self):
cash_journal = self.cash_journal_id
action = self.env["ir.actions.actions"]._for_xml_id(
"pos_session_pay_invoice.action_pos_invoice_in_control"
)
action["context"] = {
"active_ids": cash_journal.ids,
"active_name": cash_journal._name,
"pos_session_id": self.id,
}
return action
3 changes: 3 additions & 0 deletions pos_session_pay_invoice/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
* Enric Tobella <[email protected]>
* Jordi Ballester <[email protected]>
* Tecnativa (https://www.tecnativa.com):

* Carlos Lopez
11 changes: 7 additions & 4 deletions pos_session_pay_invoice/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -369,7 +368,7 @@ <h1 class="title">POS Session Pay invoice</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6eac7dbff1f6e08ae835df882a549b193c4d037be692dfd6913960c06245184b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" 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 image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/pos/tree/14.0/pos_session_pay_invoice"><img alt="OCA/pos" src="https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/pos-14-0/pos-14-0-pos_session_pay_invoice"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/pos&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" 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 image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/pos/tree/16.0/pos_session_pay_invoice"><img alt="OCA/pos" src="https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/pos-16-0/pos-16-0-pos_session_pay_invoice"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/pos&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This modules allows to pay an existing Supplier Invoice / Customer Refund, or
to collect payment for an existing Customer Invoice, from within a POS Session.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -420,7 +419,7 @@ <h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/pos/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 to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/pos/issues/new?body=module:%20pos_session_pay_invoice%0Aversion:%2014.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/pos/issues/new?body=module:%20pos_session_pay_invoice%0Aversion:%2016.0%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 @@ -436,6 +435,10 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<ul class="simple">
<li>Enric Tobella &lt;<a class="reference external" href="mailto:etobella&#64;creublanca.es">etobella&#64;creublanca.es</a>&gt;</li>
<li>Jordi Ballester &lt;<a class="reference external" href="mailto:jordi.ballester&#64;eficent.com">jordi.ballester&#64;eficent.com</a>&gt;</li>
<li>Tecnativa (<a class="reference external" href="https://www.tecnativa.com">https://www.tecnativa.com</a>):<ul>
<li>Carlos Lopez</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -445,7 +448,7 @@ <h2><a class="toc-backref" href="#toc-entry-8">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/pos/tree/14.0/pos_session_pay_invoice">OCA/pos</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/pos/tree/16.0/pos_session_pay_invoice">OCA/pos</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
96 changes: 40 additions & 56 deletions pos_session_pay_invoice/tests/test_pay_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import odoo
from odoo.tests import Form

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
from odoo.addons.point_of_sale.tests.common import TestPointOfSaleCommon


Expand All @@ -12,18 +13,8 @@ class TestSessionPayInvoice(TestPointOfSaleCommon):
@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.pos_config.cash_control = True

account = cls.env["account.account"].create(
{
"code": "test_cash_pay_invoice",
"company_id": cls.company.id,
"name": "Test",
"user_type_id": cls.env.ref("account.data_account_type_revenue").id,
"reconcile": True,
}
)

cls.invoice_out = cls.env["account.move"].create(
{
"company_id": cls.company.id,
Expand All @@ -32,19 +23,20 @@ def setUpClass(cls, chart_template_ref=None):
"invoice_date": "2016-03-12",
"move_type": "out_invoice",
"invoice_line_ids": [
0,
0,
{
"product_id": cls.product3.id,
"name": "Producto de prueba",
"account_id": account.id,
"quantity": 1.0,
"price_unit": 100.0,
},
(
0,
0,
{
"product_id": cls.product3.id,
"name": "Producto de prueba",
"quantity": 1.0,
"price_unit": 100.0,
"tax_ids": [],
},
)
],
}
)
cls.invoice_out._onchange_invoice_line_ids()
cls.invoice_out.action_post()
cls.invoice_in = cls.env["account.move"].create(
{
Expand All @@ -54,19 +46,20 @@ def setUpClass(cls, chart_template_ref=None):
"date": "2016-03-12",
"invoice_date": "2016-03-12",
"invoice_line_ids": [
0,
0,
{
"product_id": cls.product3.id,
"name": "Producto de prueba",
"account_id": account.id,
"quantity": 1.0,
"price_unit": 100.0,
},
(
0,
0,
{
"product_id": cls.product3.id,
"name": "Producto de prueba",
"quantity": 1.0,
"price_unit": 100.0,
"tax_ids": [],
},
)
],
}
)
cls.invoice_in._onchange_invoice_line_ids()
cls.invoice_in.action_post()
refund_wizard = (
cls.env["account.move.reversal"]
Expand All @@ -75,41 +68,34 @@ def setUpClass(cls, chart_template_ref=None):
active_id=cls.invoice_out.id,
active_model=cls.invoice_out._name,
)
.create({})
.create({"journal_id": cls.invoice_out.journal_id.id})
.reverse_moves()
)
cls.refund = cls.env[refund_wizard["res_model"]].browse(refund_wizard["res_id"])
cls.refund.action_post()

def test_pos_in_invoice(self):
self.assertEqual(self.invoice_in.amount_residual, 100.0)
self.pos_config.open_session_cb()
self.pos_config._action_to_open_ui()
session = self.pos_config.current_session_id
self.assertIsNotNone(session.statement_ids)
cash_statements = session.statement_ids.filtered(
lambda x: x.journal_id.type == "cash"
)
self.assertEqual(len(cash_statements), 1)
self.assertTrue(session.cash_control)
self.assertTrue(session.cash_journal_id)
session.action_pos_session_open()
cash_in = self.env["cash.invoice.in"].with_context(
active_ids=session.ids, active_model="pos.session"
)
wizard_context = session.button_show_wizard_pay_invoice()["context"]
cash_in = self.env["cash.pay.invoice"].with_context(**wizard_context)
with Form(cash_in) as form:
form.invoice_id = self.invoice_in
self.assertEqual(form.amount, -100)
cash_in.browse(form.id).run()
cash_in.browse(form.id).action_pay_invoice()
session.action_pos_session_closing_control()
session._validate_session()
session.flush()
session.refresh()
self.invoice_in.flush()
self.invoice_in.refresh()
session.invalidate_recordset()
self.invoice_in.invalidate_recordset()
self.invoice_in._compute_amount()
self.assertEqual(self.invoice_in.amount_residual, 0.0)

def test_pos_out_invoice(self):
self.assertEqual(self.invoice_out.amount_residual, 100.0)
self.pos_config.open_session_cb()
self.pos_config._action_to_open_ui()
session = self.pos_config.current_session_id
out_invoice = self.env["pos.box.cash.invoice.out"].with_context(
active_ids=session.ids,
Expand All @@ -122,15 +108,14 @@ def test_pos_out_invoice(self):
form.amount = 75
out_invoice.browse(form.id).run()
session.action_pos_session_closing_control()
session._validate_session()
session.flush()
self.invoice_out.flush()
session.invalidate_recordset()
self.invoice_out.invalidate_recordset()
self.invoice_out._compute_amount()
self.assertEqual(self.invoice_out.amount_residual, 25.0)

def test_pos_invoice_refund(self):
self.assertEqual(self.refund.amount_residual, 100.0)
self.pos_config.open_session_cb()
self.pos_config._action_to_open_ui()
session = self.pos_config.current_session_id
in_invoice = self.env["pos.box.cash.invoice.in"].with_context(
active_ids=session.ids,
Expand All @@ -142,8 +127,7 @@ def test_pos_invoice_refund(self):
self.assertEqual(form.amount, -100)
in_invoice.browse(form.id).run()
session.action_pos_session_closing_control()
session._validate_session()
session.flush()
self.invoice_out.flush()
self.refund.refresh()
session.invalidate_recordset()
self.invoice_out.invalidate_recordset()
self.refund.invalidate_recordset()
self.assertEqual(self.refund.amount_residual, 0.0)
4 changes: 2 additions & 2 deletions pos_session_pay_invoice/views/pos_session.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
</button>
<button
class="oe_stat_button"
name="%(action_pos_invoice_in_control)d"
type="action"
name="button_show_wizard_pay_invoice"
type="object"
icon="fa-level-up"
attrs="{'invisible':['|',('cash_control', '=', False), ('state', 'not in', ['opened', 'closing_control'])]}"
>
Expand Down
2 changes: 1 addition & 1 deletion pos_session_pay_invoice/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from . import cash_invoice_in
from . import cash_pay_invoice
from . import pos_box_cash_invoice_in
from . import pos_box_cash_invoice_out
47 changes: 0 additions & 47 deletions pos_session_pay_invoice/wizard/cash_invoice_in.py

This file was deleted.

21 changes: 21 additions & 0 deletions pos_session_pay_invoice/wizard/cash_pay_invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (C) 2017 Creu Blanca
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

from odoo import api, models


class CashPayInvoice(models.TransientModel):
_inherit = "cash.pay.invoice"

@api.model
def default_get(self, fields_list):
values = super().default_get(fields_list)
if "invoice_type" in fields_list and self.env.context.get("pos_session_id"):
values["invoice_type"] = "vendor"
return values

def _prepare_statement_line_vals(self):
vals = super()._prepare_statement_line_vals()
if self.env.context.get("pos_session_id"):
vals["pos_session_id"] = self.env.context.get("pos_session_id")
return vals
Loading

0 comments on commit 3c68f22

Please sign in to comment.