-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62d68a6
commit 35b9e09
Showing
7 changed files
with
188 additions
and
0 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
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,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": [], | ||
} |
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 @@ | ||
from . import account_invoice |
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,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 |
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 @@ | ||
from . import test_edi |
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,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") |
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,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> |