Skip to content

Commit

Permalink
[BKP] edi_account: backport to V12
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiMForgeFlow committed Nov 21, 2024
1 parent 62d68a6 commit 35b9e09
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 0 deletions.
1 change: 1 addition & 0 deletions edi_account/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions edi_account/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2020 Creu Blanca
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "Edi Account",
"summary": """
Define EDI Configuration for Account Moves""",
"version": "12.0.1.0.0",
"license": "LGPL-3",
"author": "Creu Blanca,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/edi",
"depends": ["account", "edi_oca", "component_event"],
"data": [
"views/account_invoice.xml",
],
"demo": [],
}
1 change: 1 addition & 0 deletions edi_account/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import account_invoice
31 changes: 31 additions & 0 deletions edi_account/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2020 Creu Blanca
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import models


class AccountInvoice(models.Model):
_name = "account.invoice"
_inherit = ["account.invoice", "edi.exchange.consumer.mixin"]

def action_invoice_open(self):
result = super().action_invoice_open()
# We will use this event to know which documents needs to be executed
if self:
self._event("on_open_account_invoice").notify(self)
return result

def action_cancel(self):
"""This could be used to notify our provider that we are not accepting the
invoice"""
result = super().action_cancel()
if self:
self._event("on_cancel_account_invoice").notify(self)
return result

def action_invoice_paid(self):
"""This could be used to notify our provider that we are paying"""
result = super().action_invoice_paid()
if self:
self._event("on_paid_account_invoice").notify(self)
return result
1 change: 1 addition & 0 deletions edi_account/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_edi
109 changes: 109 additions & 0 deletions edi_account/tests/test_edi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Copyright 2020 Creu Blanca
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import logging
from datetime import datetime

from odoo import fields

from odoo.addons.account.tests.account_test_no_chart import TestAccountNoChartCommon
from odoo.addons.component.core import Component
from odoo.addons.component.tests.common import SavepointComponentRegistryCase

_logger = logging.getLogger(__name__)


class EDIBackendTestCase(TestAccountNoChartCommon, SavepointComponentRegistryCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.setUpAdditionalAccounts()
cls.setUpAccountJournal()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.cash_journal = cls.env["account.journal"].search(
[("type", "=", "cash"), ("company_id", "=", cls.env.user.company_id.id)]
)[0]
cls.journal_sale.update_posted = True

class AccountInvoiceEventListenerDemo(Component):
_name = "account.invoice.event.listener.demo"
_inherit = "base.event.listener"

def on_open_account_invoice(self, invoice):
invoice.name = "new_name"

def on_paid_account_invoice(self, invoice):
invoice.name = "paid"

def on_cancel_account_invoice(self, invoice):
invoice.name = "cancelled"

AccountInvoiceEventListenerDemo._build_component(cls.comp_registry)
cls.comp_registry._cache.clear()
cls.test_invoice = (
cls.env["account.invoice"]
.with_context(components_registry=cls.comp_registry)
.create(
{
"partner_id": cls.partner_customer_usd.id,
"date_invoice": fields.Date.from_string("2016-01-01"),
"journal_id": cls.journal_sale.id,
"invoice_line_ids": [
(
0,
None,
{
"name": "revenue line 1",
"account_id": cls.account_revenue.id,
"quantity": 1.0,
"price_unit": 100.0,
},
),
(
0,
None,
{
"name": "revenue line 2",
"account_id": cls.account_revenue.id,
"quantity": 1.0,
"price_unit": 100.0,
},
),
],
}
)
)
cls.test_invoice.refresh()

def test_paid_move(self):
self.test_invoice.action_invoice_open()
self.assertEqual(self.test_invoice.name, "new_name")

invoice_ctx = {
"active_model": "account.invoice",
"active_ids": [self.test_invoice.id],
}
register_payments = (
self.env["account.register.payments"]
.with_context(invoice_ctx)
.create(
{
"payment_date": datetime.now().strftime("%Y-%m-%d"),
"payment_method_id": self.env.ref(
"account.account_payment_method_manual_in"
).id,
"journal_id": self.cash_journal.id,
"amount": 200.0,
}
)
)
register_payments.with_context(
components_registry=self.comp_registry
).create_payments()
self.assertEqual(self.test_invoice.name, "paid")

def test_cancel_move(self):
self.test_invoice.action_invoice_open()
self.assertEqual(self.test_invoice.name, "new_name")
self.test_invoice.action_cancel()
self.assertEqual(self.test_invoice.name, "cancelled")
28 changes: 28 additions & 0 deletions edi_account/views/account_invoice.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2020 Creu Blanca
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<odoo>
<record model="ir.ui.view" id="invoice_form">
<field name="name">account.invoice.form (in edi_account)</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form" />
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside">
<button
type="object"
class="oe_stat_button"
icon="fa-retweet"
attrs="{'invisible': [('exchange_record_count', '=', 0)]}"
name="action_view_edi_records"
>
<div class="o_form_field o_stat_info">
<span class="o_stat_value">
<field name="exchange_record_count" />
</span>
<span class="o_stat_text">EDI</span>
</div>
</button>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 35b9e09

Please sign in to comment.