Skip to content

Commit

Permalink
Merge pull request #239 from ecosoft-odoo/15.0-add-etax-replacement-r…
Browse files Browse the repository at this point in the history
…eceipt

[ADD] Create replacement etax receipt
  • Loading branch information
Saran440 authored Jan 15, 2025
2 parents d060319 + 4f17bbc commit 3c18258
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 27 deletions.
1 change: 1 addition & 0 deletions frappe_etax_service/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"security/ir.model.access.csv",
"data/purpose_code_data.xml",
"data/cron.xml",
"data/server_action.xml",
"wizards/wizard_select_etax_doctype_view.xml",
"wizards/account_move_reversal_view.xml",
"wizards/account_debit_note_view.xml",
Expand Down
16 changes: 16 additions & 0 deletions frappe_etax_service/data/server_action.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="action_create_replacement" model="ir.actions.server">
<field name="name">Update Tax Invoice number</field>
<field name="model_id" ref="account.model_account_payment" />
<field name="state">code</field>
<field name="code">
if record.tax_invoice_ids:
if not record.tax_invoice_ids.mapped('tax_invoice_number'):
record.tax_invoice_ids.write({
'tax_invoice_number': record.name,
'tax_invoice_date': record.date
})
</field>
</record>
</odoo>
19 changes: 13 additions & 6 deletions frappe_etax_service/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ class AccountMove(models.Model):
# "target": "new",
# }

def action_open_replacement_wizard(self):
self.ensure_one()
return {
"type": "ir.actions.act_window",
"name": "Create Replacement",
"res_model": "wizard.select.replacement.purpose",
"view_mode": "form",
"target": "new",
"context": {
"default_res_model": self._name,
},
}

def _get_branch_id(self):
"""
By default, core odoo do not provide branch_id field in
Expand Down Expand Up @@ -86,12 +99,6 @@ def create_replacement_etax(self):
}
).copy_data()
old_number = self.name
suffix = "-R"
if suffix in old_number:
[number, rev] = old_number.split(suffix)
res[0]["name"] = f"{number}{suffix}{int(rev) + 1}"
else:
res[0]["name"] = f"{old_number}{suffix}{1}"
res[0]["posted_before"] = self.posted_before
res[0]["payment_reference"] = self.payment_reference
res[0]["invoice_date"] = self.invoice_date
Expand Down
51 changes: 47 additions & 4 deletions frappe_etax_service/models/account_payment.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
# Copyright 2023 Kitti U.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, models
from odoo import _, fields, models
from odoo.exceptions import ValidationError


class AccountMove(models.Model):
class AccountPayment(models.Model):
_name = "account.payment"
_inherit = ["account.payment", "etax.th"]

has_create_replacement = fields.Boolean(
copy=False,
default=False,
)

def action_open_replacement_wizard(self):
self.ensure_one()
return {
"type": "ir.actions.act_window",
"name": "Create Replacement",
"res_model": "wizard.select.replacement.purpose",
"view_mode": "form",
"target": "new",
"context": {
"default_res_model": self._name,
},
}

def action_draft(self):
if self.filtered(
lambda pay: pay.etax_status in ("success", "processing", "to_process")
if (
self.filtered(
lambda pay: pay.etax_status in ("success", "processing", "to_process")
)
and not self.has_create_replacement
):
raise ValidationError(
_(
Expand All @@ -32,3 +53,25 @@ def _get_branch_id(self):
return self.reconciled_invoice_ids[0].branch_id.name
else:
return False

def create_replacement_etax(self):
"""
Create replacement receipt eTax
"""
self.ensure_one()
if not (self.state == "posted" and self.etax_status == "success"):
raise ValidationError(_("Only posted etax payment can have a substitution"))
if len(self.reconciled_invoice_ids) > 1:
raise ValidationError(_("Multiple reconciled invoices not allowed"))
res = self.with_context(include_business_fields=True).copy_data()
old_number = self.name
res[0]["posted_before"] = self.posted_before
res[0]["date"] = self.date
res[0]["ref"] = self.ref
res[0]["doc_name_template"] = self.doc_name_template.id
payment = self.create(res[0])
self.has_create_replacement = True
self.action_draft()
self.action_cancel()
self.name = old_number # Ensure name.
return payment
7 changes: 7 additions & 0 deletions frappe_etax_service/models/etax_th.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ class ETaxTH(models.AbstractModel):
copy=False,
help="Currently this field only support invoice and not payment",
)
replaced_receipt_id = fields.Many2one(
comodel_name="account.payment",
string="Replaced Receipt Payment Document",
readonly=True,
copy=False,
help="This field support replacement payment",
)
is_send_frappe = fields.Boolean(
copy=False,
)
Expand Down
11 changes: 4 additions & 7 deletions frappe_etax_service/views/account_move_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,14 @@
}"
/>
<button
string='Create Replacement e-Tax'
name="frappe_etax_service.action_select_replacement_purpose_view"
type="action"
name="action_open_replacement_wizard"
string="Create Replacement e-Tax"
type="object"
attrs="{'invisible': ['|', ('etax_status', '!=', 'success'), ('state', '!=', 'posted')]}"
/>
</xpath>
<xpath expr="//page[@id='other_tab_entry']" position="after">
<page
id="frappe_etax_service"
string="e-Tax Info"
>
<page id="frappe_etax_service" string="e-Tax Info">
<group>
<group string="e-Tax">
<field
Expand Down
27 changes: 20 additions & 7 deletions frappe_etax_service/views/account_payment_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,18 @@
type="object"
class="btn-info"
attrs="{
'invisible': ['|', '|',
'invisible': ['|',
('etax_status', 'in', ['success']),
('state', 'not in', ('posted')),
('tax_invoice_ids', '=', [])
]
}"
/>
<!-- <button
string='Create Replacement e-Tax'
name="frappe_etax_service.action_select_replacement_purpose_view"
type="action"
<button
name="action_open_replacement_wizard"
string="Create Replacement Receipt e-Tax"
type="object"
attrs="{'invisible': ['|', ('etax_status', '!=', 'success'), ('state', '!=', 'posted')]}"
/> -->
/>
</xpath>
<xpath expr="//sheet/group" position="inside">
<group name="etax_info" string="e-Tax">
Expand Down Expand Up @@ -93,6 +92,20 @@
force_save="1"
/>
</group>
<group string="Additional Information">
<field
name="replaced_receipt_id"
attrs="{'invisible': [('replaced_receipt_id', '=', False)]}"
/>
<field
name="create_purpose_code"
attrs="{'required': [('replaced_receipt_id', '!=', False)]}"
/>
<field
name="create_purpose"
attrs="{'required': [('replaced_receipt_id', '!=', False)]}"
/>
</group>
</xpath>
</field>
</record>
Expand Down
40 changes: 37 additions & 3 deletions frappe_etax_service/wizards/wizard_select_replacement_purpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,54 @@ class WizardSelectReplacementPurpose(models.TransientModel):
reason = fields.Char(
required=True,
)
res_model = fields.Char(
string="Resource Model",
default=lambda self: self.env.context.get("default_res_model", ""),
)

@api.model
def default_get(self, fields):
res = super().default_get(fields)
context = self.env.context
if context.get("default_res_model"):
res["res_model"] = context.get("default_res_model")
return res

@api.onchange("purpose_code_id")
def _onchange_purpose_code_id(self):
self.reason = self.purpose_code_id.reason

def create_replacement(self):
active_ids = self.env.context.get("active_ids", [])
move = self.env["account.move"].browse(active_ids)
if self.res_model == "account.move":
move = self.env["account.move"].browse(active_ids)
invoice_date = move.invoice_date
elif self.res_model == "account.payment":
move = self.env["account.payment"].browse(active_ids)
invoice_date = move.date

move.ensure_one()
self._check_replacement_lock_date(move.invoice_date)

self._check_replacement_lock_date(invoice_date)

# Create replacement name
old_number = move.name
suffix = "-R"
if suffix in old_number:
[number, rev] = old_number.split(suffix)
replace_name = f"{number}{suffix}{int(rev) + 1}"
else:
replace_name = f"{old_number}{suffix}{1}"
replacement = move.create_replacement_etax()
replacement.name = replace_name
replacement.create_purpose_code = self.purpose_code_id.code
replacement.create_purpose = self.reason
replacement.replaced_entry_id = move

if self.res_model == "account.move":
replacement.replaced_entry_id = move
elif self.res_model == "account.payment":
replacement.replaced_receipt_id = move

return {
"type": "ir.actions.act_window",
"views": [(False, "form")],
Expand Down

0 comments on commit 3c18258

Please sign in to comment.