Skip to content

Commit

Permalink
[IMP] Improved Suggested Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Chanakya-SerpentCS committed Dec 10, 2019
1 parent b48b3a5 commit 32a857b
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 219 deletions.
7 changes: 2 additions & 5 deletions account_invoice_refund_reason/README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Overview
========
Description
===========

This module allows you to define a list of reasons to create a credit note from an invoice and report on them.

Expand All @@ -11,9 +11,6 @@ Create the different reasons you want to provide users
Usage
=====

Operations
==========

Go to Accounting > Customers > Invoices (or Accounting > Vendors > Bills)
Select an open invoice (or bill)
Click on the "Add Credit Note"
Expand Down
2 changes: 1 addition & 1 deletion account_invoice_refund_reason/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2019 - TODAY, Open Source Integrators
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2019 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand Down
8 changes: 5 additions & 3 deletions account_invoice_refund_reason/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2019 - TODAY, Open Source Integrators
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2019 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand All @@ -8,7 +8,8 @@
"summary": "Account Invoice Refund Reason.",
'category': 'Accounting',
'author': "Open Source Integrators, "
"Serpent CS, ",
"Odoo Community Association (OCA), ",
"Serpent CS, "
'website': 'https://github.com/OCA/account-invoicing.git',
'data': ['security/ir.model.access.csv',
'data/account.invoice.refund.reason.csv',
Expand All @@ -17,5 +18,6 @@
'wizard/account_invoice_refund_view.xml'],
'depends': ['account'],
'license': 'AGPL-3',
'installable': True,
'development_status': 'Beta',
'maintainers': ['max3903']
}
2 changes: 1 addition & 1 deletion account_invoice_refund_reason/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2019 - TODAY, Open Source Integrators
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2019 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand Down
2 changes: 1 addition & 1 deletion account_invoice_refund_reason/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2019 - TODAY, Open Source Integrators
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2019 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2019 - TODAY, Open Source Integrators
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2019 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand All @@ -9,4 +9,4 @@ class AccountInvoiceRefundReason(models.Model):
_name = 'account.invoice.refund.reason'
_description = 'Account Invoice refund Reasons'

name = fields.Char('Name', required=True)
name = fields.Char('Name', required=True, translate=True)
3 changes: 2 additions & 1 deletion account_invoice_refund_reason/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_account_invoice_refund_reason,access_account_invoice_refund_reason,model_account_invoice_refund_reason,base.group_user,1,1,1,0
access_account_invoice_refund_reason_user,access_account_invoice_refund_reason_user,model_account_invoice_refund_reason,account.group_account_invoice,1,0,0,0
access_account_invoice_refund_reason_manager,access_account_invoice_refund_reason_manager,model_account_invoice_refund_reason,account.group_account_manager,1,1,1,1
Original file line number Diff line number Diff line change
@@ -1,44 +1,39 @@

<odoo>
<data>

<record id="view_account_invoice_refund_reason" model="ir.ui.view">
<field name="name">account.invoice.refund.reason.form</field>
<field name="model">account.invoice.refund.reason</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name"/>
</group>
</sheet>
</form>
</field>
</record>

<record id="view_account_invoice_refund_reason_tree" model="ir.ui.view">
<field name="name">account.invoice.refund.reason.tree</field>
<field name="model">account.invoice.refund.reason</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
</tree>
</field>
</record>
<record id="view_account_invoice_refund_reason" model="ir.ui.view">
<field name="name">account.invoice.refund.reason.form</field>
<field name="model">account.invoice.refund.reason</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name"/>
</group>
</sheet>
</form>
</field>
</record>

<record id="refund_reason_action" model="ir.actions.act_window">
<field name="name">Refund Reasons</field>
<field name="res_model">account.invoice.refund.reason</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<record id="view_account_invoice_refund_reason_tree" model="ir.ui.view">
<field name="name">account.invoice.refund.reason.tree</field>
<field name="model">account.invoice.refund.reason</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
</tree>
</field>
</record>

<menuitem
id="refund_reasons_menu"
name="Refund Reasons"
parent="account.account_management_menu"
action="refund_reason_action"
groups="base.group_user"/>
<record id="refund_reason_action" model="ir.actions.act_window">
<field name="name">Refund Reasons</field>
<field name="res_model">account.invoice.refund.reason</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>

</data>
<menuitem
id="refund_reasons_menu"
name="Refund Reasons"
parent="account.account_management_menu"
action="refund_reason_action"
groups="base.group_user"/>
</odoo>
57 changes: 26 additions & 31 deletions account_invoice_refund_reason/views/account_invoice_view.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@

<odoo>
<data>

<record id="extended_view_account_invoice" model="ir.ui.view">
<field name="name">extended.account.invoice.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='reference']" position="after">
<field name="reason_id" attrs="{'invisible': [('type','not in', ['in_refund', 'out_refund'])]}" readonly="1"/>
</xpath>
<xpath expr="//page[@name='other_info']/group/group[1]/field[@name='name']" position="attributes">
<attribute name="attrs">{'invisible': [('type','in', ['in_refund', 'out_refund'])]}</attribute>
</xpath>
</field>
</record>

<record id="extended_view_account_invoice_supplier_form" model="ir.ui.view">
<field name="name">extended.account.invoice.supplier.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_supplier_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='other_info']/group/group[1]/field[@name='name']" position="attributes">
<attribute name="attrs">{'invisible': [('type','in', ['in_refund', 'out_refund'])]}</attribute>
</xpath>
<xpath expr="//field[@name='date']" position="after">
<field name="reason_id" attrs="{'invisible': [('type','not in', ['in_refund', 'out_refund'])]}" readonly="1"/>
</xpath>
</field>
</record>
<record id="extended_view_account_invoice" model="ir.ui.view">
<field name="name">extended.account.invoice.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='reference']" position="after">
<field name="reason_id" attrs="{'invisible': [('reason_id', '=', False)]}" readonly="1"/>
</xpath>
<xpath expr="//page[@name='other_info']/group/group[1]/field[@name='name']" position="attributes">
<attribute name="attrs">{'invisible': [('reason_id','!=', False)]}</attribute>
</xpath>
</field>
</record>

</data>
<record id="extended_view_account_invoice_supplier_form" model="ir.ui.view">
<field name="name">extended.account.invoice.supplier.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_supplier_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='other_info']/group/group[1]/field[@name='name']" position="attributes">
<attribute name="attrs">{'invisible': [('reason_id','!=', False)]}</attribute>
</xpath>
<xpath expr="//field[@name='date']" position="after">
<field name="reason_id" attrs="{'invisible': [('reason_id', '=', False)]}" readonly="1"/>
</xpath>
</field>
</record>
</odoo>
2 changes: 1 addition & 1 deletion account_invoice_refund_reason/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2019 - TODAY, Open Source Integrators
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2019 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand Down
128 changes: 13 additions & 115 deletions account_invoice_refund_reason/wizard/account_invoice_refund.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Copyright (C) 2019 - TODAY, Open Source Integrators
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2019 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.tools.safe_eval import safe_eval
from odoo import api, fields, models


class AccountInvoiceRefund(models.TransientModel):
Expand All @@ -19,114 +17,14 @@ def _onchange_reason_id(self):
self.description = self.reason_id.name

@api.multi
def compute_refund(self, mode='refund'):
inv_obj = self.env['account.invoice']
inv_tax_obj = self.env['account.invoice.tax']
inv_line_obj = self.env['account.invoice.line']
context = dict(self._context or {})
xml_id = False

for form in self:
created_inv = []
date = False
description = False
for inv in inv_obj.browse(context.get('active_ids')):
if inv.state in ['draft', 'cancel']:
raise UserError(
_('Cannot create credit note for the draft/cancelled\
invoice.'))
if inv.reconciled and mode in ('cancel', 'modify'):
raise UserError(
_('Cannot create a credit note for the invoice which is\
already reconciled, invoice should be unreconciled\
first, then only you can add\
credit note for this invoice.'))

date = form.date or False
description = form.description or inv.name
refund = inv.refund(form.date_invoice, date,
description, inv.journal_id.id)
refund.reason_id = self.reason_id
created_inv.append(refund.id)
if mode in ('cancel', 'modify'):
movelines = inv.move_id.line_ids
to_reconcile_ids = {}
to_reconcile_lines = self.env['account.move.line']
for line in movelines:
if line.account_id.id == inv.account_id.id:
to_reconcile_lines += line
to_reconcile_ids.setdefault(
line.account_id.id, []).append(line.id)
if line.reconciled:
line.remove_move_reconcile()
refund.action_invoice_open()
for tmpline in refund.move_id.line_ids:
if tmpline.account_id.id == inv.account_id.id:
to_reconcile_lines += tmpline
to_reconcile_lines.filtered(
lambda l: l.reconciled is False).reconcile()
if mode == 'modify':
invoice = inv.read(
inv_obj._get_refund_modify_read_fields())
invoice = invoice[0]
del invoice['id']
invoice_lines = inv_line_obj.browse(
invoice['invoice_line_ids'])
invoice_lines = inv_obj.with_context(
mode='modify')._refund_cleanup_lines(invoice_lines)
tax_lines = inv_tax_obj.browse(invoice['tax_line_ids'])
tax_lines = inv_obj._refund_cleanup_lines(tax_lines)
invoice.update({
'type': inv.type,
'date_invoice': form.date_invoice,
'state': 'draft',
'number': False,
'invoice_line_ids': invoice_lines,
'tax_line_ids': tax_lines,
'date': date,
'origin': inv.origin,
'fiscal_position_id': inv.fiscal_position_id.id,
})
for field in inv_obj._get_refund_common_fields():
if inv_obj._fields[field].type == 'many2one':
invoice[field] = invoice[field] and\
invoice[field][0]
else:
invoice[field] = invoice[field] or False
inv_refund = inv_obj.create(invoice)
body = _('Correction of <a href=# \
data-oe-model=account.invoice data-oe-id=%d>%s</a>\
<br>Reason: %s') % (
inv.id, inv.number, description)
inv_refund.message_post(body=body)
if inv_refund.payment_term_id.id:
inv_refund._onchange_payment_term_date_invoice()
created_inv.append(inv_refund.id)
xml_id = inv.type == 'out_invoice' and\
'action_invoice_out_refund' or \
inv.type == 'out_refund' and 'action_invoice_tree1' or \
inv.type == 'in_invoice' and 'action_invoice_in_refund' or\
inv.type == 'in_refund' and 'action_invoice_tree2'
if xml_id:
result = self.env.ref('account.%s' % (xml_id)).read()[0]
if mode == 'modify':
# When refund method is `modify` then it will directly open\
# the new draft bill/invoice in form view
if inv_refund.type == 'in_invoice':
view_ref = self.env.ref('account.invoice_supplier_form')
else:
view_ref = self.env.ref('account.invoice_form')
form_view = [(view_ref.id, 'form')]
if 'views' in result:
result['views'] = form_view + \
[(state, view)
for state, view in result['views'] if view != 'form']
else:
result['views'] = form_view
result['res_id'] = inv_refund.id
else:
invoice_domain = safe_eval(result['domain'])
invoice_domain.append(('id', 'in', created_inv))
result['domain'] = invoice_domain
return result
return True
def invoice_refund(self):
res = super(AccountInvoiceRefund, self).invoice_refund()
data_refund = self.read(['filter_refund'])[0]['filter_refund']
if data_refund == 'modify':
inv_id = res.get('res_id')
else:
inv_id = res.get('domain')[1][2][0]
if inv_id:
invoice = self.env['account.invoice'].browse(inv_id)
invoice.reason_id = self.reason_id
return res
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@

<odoo>
<data>

<record id="extended_view_account_invoice_refund" model="ir.ui.view">
<field name="name">extended.account.invoice.refund.form</field>
<field name="model">account.invoice.refund</field>
<field name="inherit_id" ref="account.view_account_invoice_refund"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='description']" position="attributes">
<attribute name="invisible">1</attribute>
<attribute name="required">0</attribute>
</xpath>
<xpath expr="//group[3]" position="inside">
<field name="reason_id" required="1"/>
</xpath>
</field>
</record>

</data>
<record id="extended_view_account_invoice_refund" model="ir.ui.view">
<field name="name">extended.account.invoice.refund.form</field>
<field name="model">account.invoice.refund</field>
<field name="inherit_id" ref="account.view_account_invoice_refund"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='description']" position="attributes">
<attribute name="invisible">1</attribute>
<attribute name="required">0</attribute>
</xpath>
<xpath expr="//group[3]" position="inside">
<field name="reason_id" required="1"/>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 32a857b

Please sign in to comment.