Skip to content

Commit

Permalink
[ADD] account_invoice_date
Browse files Browse the repository at this point in the history
  • Loading branch information
dsolanki-initos committed Feb 21, 2023
1 parent 71af99f commit 9d7a5c8
Show file tree
Hide file tree
Showing 17 changed files with 388 additions and 0 deletions.
71 changes: 71 additions & 0 deletions account_invoice_date/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
====================
Account Invoice Date
====================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--invoicing-lightgray.png?logo=github
:target: https://github.com/OCA/account-invoicing/tree/15.0/account_invoice_date_due
:alt: OCA/account-invoicing
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-invoicing-15-0/account-invoicing-15-0-account_invoice_date_due
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/95/15.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

Usage
=====

When an customer invoice or vendor bill is validated from Draft to Open automatically, the invoice/bill date is set to current date. If an invoice/bill is validated from Draft to Open manually, a window is displayed to query the invoice/bill date from the user.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-invoicing/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/account-invoicing/issues/new?body=module:%20account_invoice_date_due%0Aversion:%2015.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.

Credits
=======

Authors
~~~~~~~

* initOS

Contributors
~~~~~~~~~~~~

* isufi kapasi <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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/account-invoicing <https://github.com/OCA/account-invoicing/tree/15.0/account_invoice_date>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions account_invoice_date/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# © 2022 Thomas Rehn (initOS GmbH)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models, wizard
29 changes: 29 additions & 0 deletions account_invoice_date/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# © 2022 Thomas Rehn (initOS GmbH)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Account Invoice Date",
"summary": """
When an invoice or bill is validated from Draft to Open automatically,
the invoice/bill date is set to current date.
If an invoice/bill is validated from Draft to Open manually,
a window is displayed to query the invoice/bill date from the user.
""",
"category": "Accounting",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"depends": [
"account",
],
"data": [
"security/ir.model.access.csv",
"wizard/account_voucher_proforma_date_view.xml",
"views/account_move_view.xml",
],
"assets": {
"web.assets_backend": [
"account_invoice_date/static/src/js/tours/invoice_date.js",
],
},
"author": "initOS,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-invoicing",
}
4 changes: 4 additions & 0 deletions account_invoice_date/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# © 2022 Thomas Rehn (initOS GmbH)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import account_move
25 changes: 25 additions & 0 deletions account_invoice_date/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from odoo import models


class AccountMove(models.Model):
_inherit = "account.move"

def open_invoice_date_wizard(self):
if self.invoice_date:
self.action_post()
else:
if self.move_type == "out_invoice":
name = "Confirm Invoice"
else:
name = "Confirm Bill"

Check warning on line 14 in account_invoice_date/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_date/models/account_move.py#L14

Added line #L14 was not covered by tests
action = self.env.ref(
"account_invoice_date.view_account_voucher_proforma_date"
)
return {
"name": name,
"view_type": "form",
"target": "new",
"res_model": "account.voucher.proforma.date",
"views": [(action.id, "form")],
"type": "ir.actions.act_window",
}
1 change: 1 addition & 0 deletions account_invoice_date/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* isufi kapasi <[email protected]>
1 change: 1 addition & 0 deletions account_invoice_date/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When an invoice is validated from Draft to Open automatically, the invoice date is set to current date.If an invoice is validated from Draft to Open manually, a window is displayed to query the invoice date from the user.
3 changes: 3 additions & 0 deletions account_invoice_date/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#. Go to Invoice > Click Create > Create new invoice.
#. Click on "Confirm" button.
#. Select the date and Click on "Open invoice" button.
2 changes: 2 additions & 0 deletions account_invoice_date/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
account_invoice_date.access_account_voucher_proforma_date,access_account_voucher_proforma_date,account_invoice_date.model_account_voucher_proforma_date,base.group_user,1,1,1,1
1 change: 1 addition & 0 deletions account_invoice_date/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_invoice_date
75 changes: 75 additions & 0 deletions account_invoice_date/tests/test_invoice_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import logging

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

from odoo.addons.account.tests.common import AccountTestInvoicingCommon

_logger = logging.getLogger(__name__)


@tagged("post_install", "-at_install")
class TestinvoiceDate(AccountTestInvoicingCommon):
def setUp(self):
super(TestinvoiceDate, self).setUp()
self.partner_test = (
self.env["res.partner"]
.sudo()
.create({"name": "Test User", "email": "[email protected]"})
)

def create_invoice(self, invoice_date):
return self.env["account.move"].create(
{
"move_type": "out_invoice",
"partner_id": self.partner_test.id,
"invoice_date": invoice_date,
"currency_id": self.currency_data["currency"].id,
"invoice_line_ids": [
(
0,
0,
{
"name": "test line",
"price_unit": 5,
"quantity": 1,
"account_id": self.company_data[
"default_account_revenue"
].id,
},
)
],
}
)

def test_invoice_has_date(self):
"""This method has an invoice that has a date
and it will not trigger the confirm date wizard"""
date = fields.Date.from_string("2023-02-05")
invoice = self.create_invoice(date)
inv_date = invoice.invoice_date
invoice.open_invoice_date_wizard()
# Compare invoice_date is same as before action_post()
self.assertEqual(invoice.invoice_date, inv_date)
self.assertTrue(invoice.state == "posted")

def test_invoice_has_not_date(self):
"""This method triggers the wizard to fill
in the date of the invoice"""
date = False
invoice = self.create_invoice(date)
date_wizard = invoice.open_invoice_date_wizard()
if date_wizard:
ctx = {
"active_model": invoice._name,
"active_ids": invoice.ids,
"active_id": invoice.ids,
}
wizard = (
self.env["account.voucher.proforma.date"]
.with_context(**ctx)
.create({"date": fields.Date.from_string("2023-02-10")})
)
wizard.with_context(**ctx).action_post()
# Checks that wizard date is written in invoice
self.assertTrue(invoice.invoice_date == fields.Date.from_string("2023-02-10"))
42 changes: 42 additions & 0 deletions account_invoice_date/views/account_move_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_move_form" model="ir.ui.view">
<field name="name">account.move.form</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form" />
<field name="arch" type="xml">
<xpath expr="//button[@name='action_post'][1]" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//button[@name='action_post'][2]" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<button name="action_post" position="after">
<button
name="open_invoice_date_wizard"
type="object"
string="Confirm"
class="oe_highlight"
attrs="{'invisible': ['|', '|', ('state', '!=', 'draft'), ('auto_post', '=', True), ('move_type', '!=', 'entry')]}"
groups="account.group_account_invoice"
/>
<button
name="open_invoice_date_wizard"
string="Confirm"
class="oe_highlight"
type="object"
groups="account.group_account_invoice"
attrs="{'invisible': ['|', '|', '|', ('state', '!=', 'draft'), ('auto_post', '=',True),('move_type','=','entry'),('display_inactive_currency_warning','=',True)]}"
/>
<button
name="%(account_invoice_date.action_credit_invoice_customer)d"
type="action"
string="Confirm"
class="oe_highlight"
attrs="{'invisible': ['|','|',('move_type','!=','out_refund'),('state','!=','draft'),('invoice_date', '!=', False)]}"
groups="account.group_account_invoice"
/>
</button>
</field>
</record>
</odoo>
4 changes: 4 additions & 0 deletions account_invoice_date/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# © 2022 Thomas Rehn (initOS GmbH)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import account_voucher_proforma_date
36 changes: 36 additions & 0 deletions account_invoice_date/wizard/account_voucher_proforma_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# © 2022 Thomas Rehn (initOS GmbH)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging

from odoo import api, fields, models

_logger = logging.getLogger(__name__)


class AccountVoucherProformaDate(models.TransientModel):
_name = "account.voucher.proforma.date"
_description = "Account Voucher Proforma Date"

date = fields.Date(
string="Date of invoice", required=True, default=fields.Date.context_today
)
invoice_type = fields.Char()

@api.model
def default_get(self, default_fields):
res = super(AccountVoucherProformaDate, self).default_get(default_fields)
invoice_id = self.env.context.get("active_id")
invoice = self.env["account.move"].browse(invoice_id)
if invoice:
res["invoice_type"] = invoice.move_type
return res

def action_post(self):
invoice_id = False
if self.env.context.get("active_model") == "account.move":
invoice_id = self.env.context.get("active_id")
assert invoice_id, "Could not determine invoice to open"
invoice = self.env["account.move"].browse(invoice_id)
invoice.invoice_date = self.date
invoice.action_post()
83 changes: 83 additions & 0 deletions account_invoice_date/wizard/account_voucher_proforma_date_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_account_voucher_proforma_date" model="ir.ui.view">
<field name="name">view.account.voucher.proforma.date</field>
<field name="model">account.voucher.proforma.date</field>
<field name="arch" type="xml">
<form>
<group>
<field name="invoice_type" invisible="1" />
<field
name="date"
string="Please enter invoice date"
attrs="{'invisible' : ['|',('invoice_type','=','in_invoice'),('invoice_type','=','in_refund')]}"
/>
<field
name="date"
string="Please enter bill date"
attrs="{'invisible' : ['|',('invoice_type','=','out_invoice'),('invoice_type','=','out_refund')]}"
/>

</group>
<footer>
<button
string='Confirm'
name="action_post"
default_focus="1"
type="object"
class="oe_highlight"
attrs="{'invisible' : ['|',('invoice_type','=','in_invoice'),('invoice_type','=','in_refund')]}"
/>
<button
string='Confirm'
name="action_post"
default_focus="1"
type="object"
class="oe_highlight"
attrs="{'invisible' : ['|',('invoice_type','=','out_invoice'),('invoice_type','=','out_refund')]}"
/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>

<record id="action_invoice_customer" model="ir.actions.act_window">
<field name="name">Open invoice</field>
<field name="res_model">account.voucher.proforma.date</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_account_voucher_proforma_date" />
<field name="target">new</field>
</record>

<record id="view_account_credit_voucher_proforma_date" model="ir.ui.view">
<field name="name">view.account.credit.voucher.proforma.date</field>
<field name="model">account.voucher.proforma.date</field>
<field name="arch" type="xml">
<form>
<group>
<field name="date" string="Please enter credit note date" />
</group>
<footer>
<button
string='Open credit note'
name="action_post"
type="object"
class="oe_highlight"
/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>

<record id="action_credit_invoice_customer" model="ir.actions.act_window">
<field name="name">Open credit note</field>
<field name="res_model">account.voucher.proforma.date</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_account_credit_voucher_proforma_date" />
<field name="target">new</field>
</record>
</odoo>
Loading

0 comments on commit 9d7a5c8

Please sign in to comment.