Skip to content

Commit

Permalink
[MIG] edi_account_oca: Migration to V12
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiMForgeFlow committed Nov 27, 2024
1 parent fda0e97 commit 381a8eb
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 101 deletions.
6 changes: 3 additions & 3 deletions edi_account_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
{
"name": "Edi Account",
"summary": """
Define EDI Configuration for Account Moves""",
"version": "16.0.1.1.0",
Define EDI Configuration for Account Invoices""",
"version": "12.0.1.1.0",
"license": "LGPL-3",
"author": "Creu Blanca,Odoo Community Association (OCA)",
"maintainers": ["etobella"],
Expand All @@ -15,7 +15,7 @@
"data": [
"views/account_journal.xml",
"views/res_partner.xml",
"views/account_move.xml",
"views/account_invoice.xml",
"views/edi_exchange_record.xml",
],
"demo": [],
Expand Down
2 changes: 1 addition & 1 deletion edi_account_oca/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import account_move
from . import account_invoice
37 changes: 37 additions & 0 deletions edi_account_oca/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2020 Creu Blanca
# Copyright 2024 ForgeFlow
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import fields, models


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

disable_edi_auto = fields.Boolean(
readonly=True,
states={"draft": [("readonly", False)]},
)

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
36 changes: 0 additions & 36 deletions edi_account_oca/models/account_move.py

This file was deleted.

1 change: 1 addition & 0 deletions edi_account_oca/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* Enric Tobella <[email protected]>
* Jordi Masvidal <[email protected]>
97 changes: 51 additions & 46 deletions edi_account_oca/tests/test_edi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,59 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import logging
from datetime import datetime

from odoo import fields
from odoo.tests.common import tagged

from odoo.addons.account.tests.common import AccountTestInvoicingCommon
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 TransactionComponentRegistryCase
from odoo.addons.component.tests.common import SavepointComponentRegistryCase

_logger = logging.getLogger(__name__)


@tagged("-at_install", "post_install")
class EDIBackendTestCase(AccountTestInvoicingCommon, TransactionComponentRegistryCase):
class EDIBackendTestCase(TestAccountNoChartCommon, SavepointComponentRegistryCase):
@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
cls._setup_registry(cls)
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 AccountMoveEventListenerDemo(Component):
_name = "account.move.event.listener.demo"
class AccountInvoiceEventListenerDemo(Component):
_name = "account.invoice.event.listener.demo"
_inherit = "base.event.listener"

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

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

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

AccountMoveEventListenerDemo._build_component(cls.comp_registry)
AccountInvoiceEventListenerDemo._build_component(cls.comp_registry)
cls.comp_registry._cache.clear()
cls.test_move = (
cls.env["account.move"]
cls.test_invoice = (
cls.env["account.invoice"]
.with_context(components_registry=cls.comp_registry)
.create(
{
"move_type": "out_invoice",
"partner_id": cls.partner_a.id,
"date": fields.Date.from_string("2016-01-01"),
"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.company_data[
"default_account_revenue"
].id,
"account_id": cls.account_revenue.id,
"quantity": 1.0,
"price_unit": 100.0,
},
Expand All @@ -62,43 +64,46 @@ def on_cancel_account_move(self, move):
None,
{
"name": "revenue line 2",
"account_id": cls.company_data[
"default_account_revenue"
].id,
"account_id": cls.account_revenue.id,
"quantity": 1.0,
"price_unit": 100.0,
"tax_ids": [
(6, 0, cls.company_data["default_tax_sale"].ids)
],
},
),
],
}
)
)
cls.test_move.invalidate_recordset()
cls.test_invoice.refresh()

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

payment_action = self.test_move.action_register_payment()
payment = (
self.env[payment_action["res_model"]]
.with_context(**payment_action["context"])
invoice_ctx = {
"active_model": "account.invoice",
"active_ids": [self.test_invoice.id],
}
register_payments = (
self.env["account.register.payments"]
.with_context(invoice_ctx)
.create(
{
"journal_id": self.company_data["default_journal_bank"].id,
"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,
}
)
)
payment.with_context(
register_payments.with_context(
components_registry=self.comp_registry
).action_create_payments()
self.assertEqual(self.test_move.name, "paid")
).create_payments()
self.assertEqual(self.test_invoice.name, "paid")

def test_cancel_move(self):
self.test_move.action_post()
self.assertEqual(self.test_move.name, "new_name")
self.test_move.button_cancel()
self.assertEqual(self.test_move.name, "cancelled")
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")
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2020 Creu Blanca
Copyright 2024 ForgeFlow
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<odoo>
<record model="ir.ui.view" id="account_move_form_view">
<field name="name">account.move.form (in edi_account)</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form" />
<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">
<group name="accounting_info_group" position="after">
<group name="edi_invoice_group" string="Electronic Data Interchange">
<field name="edi_disable_auto" />
</group>
</group>
<xpath expr="//div[@name='button_box']" position="inside">
<button
type="object"
Expand Down
2 changes: 1 addition & 1 deletion edi_account_oca/views/account_journal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_journal_form" />
<field name="arch" type="xml">
<xpath expr="//group[@name='group_alias_edit']" position="after">
<xpath expr="//group[@name='group_alias']" position="after">
<group name="edi_configuration" string="EDI Configuration" />
</xpath>
</field>
Expand Down
10 changes: 5 additions & 5 deletions edi_account_oca/views/edi_exchange_record.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

<record
model="ir.actions.act_window"
id="act_open_edi_exchange_record_account_move_view"
id="act_open_edi_exchange_record_account_invoice_view"
>
<field name="name">Account Moves Exchange Record</field>
<field name="name">Account Invoice Exchange Records</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">edi.exchange.record</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('model', '=', 'account.move')]</field>
<field name="domain">[('model', '=', 'account.invoice')]</field>
<field name="context">{}</field>
</record>
<menuitem
Expand All @@ -22,8 +22,8 @@
/>
<menuitem
id="menu_account_edi_exchange_record"
name="Moves"
action="act_open_edi_exchange_record_account_move_view"
name="Invoices"
action="act_open_edi_exchange_record_account_invoice_view"
parent="menu_account_edi_root"
sequence="20"
/>
Expand Down

0 comments on commit 381a8eb

Please sign in to comment.