Skip to content

Commit

Permalink
BAH-3748 | Added. Multi Invoice in single payment process … (#152)
Browse files Browse the repository at this point in the history
* [Karthi] | BAH-3748 | Added. Multi Invoice in single payment process module has been enabled.

* [Karthi] | BAH-3752 | Refactor. Purchase Order Order deadline fields has been enabled (#153)

* [Karthi] | BAH-3750 | Refactor. Balance field should be a non-editable field. (#155)

* BAH-3752 | Refactor. Use ordered date for purchase order register (#157)

* BAH-3752 | Refactor. Use ordered date for purchase order register date field (#158)

* [Rahul] | BAH-3697 | Add. Syncable Units Mapper

* Refactor. Bundling of community modules in docker image (#160)

* BAH-3748 | Refactor. Module metadata

* BAH-3778 | Add, Field for showing invoice total after calculating discount and round off

* BAH-3748 | Refactor. Assigning of payments and credit invoices

* BAH-3748 | Fix. Map credit notes as credit invoice lines

* BAH-3748 | Refactor. Variable naming

* BAH-3748 | Add. Reset credit invoice allocations when payment is reset

* BAH-3748 | Add. Configurable property for payments customisation feature

* BAH-3748 | Fix. Names for Bahmni Custom configurations to allow extensions

* BAH-3748 | Refactor.Remove unused files as these are refactored as extensions

* BAH-3748 | Refactor. Add all customisations behind configuration

* BAH-3748 | Refactor. Re-order function definitions to improve readability

* BAH-3748 | Refactor. Model and variable naming to improve readability

* BAH-3748 | Add. Bahmni Payments module to Dockerfile

* BAH-3748 | Refactor. Fix file formatting

* BAH-3748 | Add. Validation for payment amounts

* BAH-3748 | Fix. Module path

* BAH-3748 | Refactor. Field name for current_outstanding

---------

Co-authored-by: MOHANKUMAR T <[email protected]>
Co-authored-by: Rahul Ramesh <[email protected]>
Co-authored-by: MOHANKUMAR T <[email protected]>
  • Loading branch information
4 people authored May 9, 2024
1 parent d503767 commit 7b4fc83
Show file tree
Hide file tree
Showing 16 changed files with 942 additions and 83 deletions.
40 changes: 20 additions & 20 deletions bahmni_account/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@
from odoo import fields, models, api, _
from odoo.exceptions import UserError, ValidationError
import logging

_logger = logging.getLogger(__name__)


class AccountInvoice(models.Model):
_inherit = 'account.move'
order_id = fields.Many2one('sale.order',string="Sale ID")
discount_type = fields.Selection([('none', 'No Discount'), ('fixed', 'Fixed'), ('percentage', 'Percentage')], string="Discount Method", default='none')
order_id = fields.Many2one('sale.order', string="Sale ID")

discount_type = fields.Selection([('none', 'No Discount'),
('fixed', 'Fixed'),
('percentage', 'Percentage')],
string="Discount Method",
default='none')
discount = fields.Monetary(string="Discount")
discount_percentage = fields.Float(string="Discount Percentage")
disc_acc_id = fields.Many2one('account.account',string="Discount Account Head" ,domain=[('account_type', '=', 'income_other')])
disc_acc_id = fields.Many2one('account.account', string="Discount Account Head",
domain=[('account_type', '=', 'income_other')])
round_off_amount = fields.Monetary(string="Round Off Amount")
invoice_total = fields.Monetary(string='Invoice Total', compute='_compute_invoice_total', readonly=True)
invoice_total = fields.Monetary(
string='Invoice Total',
compute='_compute_invoice_total', readonly=True
)

@contextmanager
def _check_balanced(self, container):
Expand Down Expand Up @@ -57,7 +68,7 @@ def button_dummy(self):

def action_post(self):
for inv in self:
final_invoice_value = (inv.amount_total - inv.discount ) + inv.round_off_amount
final_invoice_value = (inv.amount_total - inv.discount) + inv.round_off_amount
for move_line in inv.line_ids:
if move_line.display_type == 'payment_term':
if inv.move_type == 'out_invoice':
Expand All @@ -69,27 +80,16 @@ def action_post(self):
@api.depends('discount', 'discount_percentage', 'amount_total', 'round_off_amount')
def _compute_invoice_total(self):
for invoice in self:
invoice.invoice_total = (invoice.amount_total - invoice.discount ) + invoice.round_off_amount
invoice.invoice_total = (invoice.amount_total - invoice.discount) + invoice.round_off_amount


class AccountPayment(models.Model):
_inherit = 'account.payment'

def invoice_search(self):
""" Using ref find the invoice obj """
return self.env['account.move'].search([('id', '=', self.reconciled_invoice_ids.id),('move_type', '=', 'out_invoice')], limit=1)

def total_receivable(self):
receivable = 0.0
if self.partner_id:
self._cr.execute("""select sum(amount_residual) from account_move where
amount_residual > 0 and partner_id = %s
""", (self.partner_id.id,))
outstaning_value = self._cr.fetchall()
if outstaning_value[0][0] != None:
receivable = outstaning_value[0][0]
else:
receivable = 0.00
return receivable
return self.env['account.move'].search(
[('id', '=', self.reconciled_invoice_ids.id), ('move_type', '=', 'out_invoice')], limit=1)

def generate_report_action(self):
return self.env.ref("bahmni_account.account_summarized_invoices_payment").report_action(self)
131 changes: 73 additions & 58 deletions bahmni_account/views/account_invoice_view.xml
Original file line number Diff line number Diff line change
@@ -1,61 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="inherit_invoice_form" model="ir.ui.view">
<field name="name">inherit.invoice.form</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='tax_totals']" position="after">
<field name="amount_untaxed" widget='monetary' options="{'currency_field': 'currency_id'}"/>
<field name="amount_tax" widget='monetary' options="{'currency_field': 'currency_id'}"/>
<field name="discount_type" required="1" attrs="{'invisible': [('amount_untaxed', '=', 0.00)], 'readonly': [('state', '!=', 'draft')]}"/>
<field name="discount_percentage" widget='monetary' options="{'currency_field': 'currency_id'}" attrs="{'readonly': ['|',('state', '!=', 'draft'),('discount_type', '=', 'fixed')],'invisible': [('discount_type', 'in', ('fixed','none'))]}"/>
<field name="discount" widget='monetary' options="{'currency_field': 'currency_id'}" attrs="{'readonly': ['|',('state', '!=', 'draft'),('discount_type', '=', 'percentage')],'invisible': [('discount_type', 'in', ('none'))]}"/>
<field name="disc_acc_id" attrs="{'readonly': [('state', '!=', 'draft')],'required': [('discount', '!=', 0.0)],'invisible': ['|', ('discount_type', '=', 'none'),('discount', '=', 0.0)]}"/>
<field name="round_off_amount" widget='monetary' attrs="{'readonly': [('state', '!=', 'draft')]}" options="{'currency_field': 'currency_id'}"/>
<div class="oe_subtotal_footer_separator oe_inline o_td_label">
<label for="invoice_total"/>
</div>
<field name="invoice_total" nolabel="1" class="oe_subtotal_footer_separator" widget='monetary' options="{'currency_field': 'currency_id'}"/>
</xpath>
</field>
</record>
<record id="inherit_view_invoice_tree_bahmni" model="ir.ui.view">
<field name="name">Invoice View Changes</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_invoice_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<field name="partner_id"/>
</xpath>
<xpath expr="//field[@name='payment_state']" position="before">
<field name="invoice_total" sum="Total" optional="show"/>
<field name="amount_residual" sum="Total" optional="show"/>
</xpath>
</field>
</record>
<record id="account.action_move_out_invoice_type" model="ir.actions.act_window">
<field name="name">Customer Invoices</field>
<field name="res_model">account.move</field>
<field name="view_mode">tree,kanban,form,pivot,graph</field>
<field eval="False" name="view_id"/>
<field name="domain">[('move_type','in',('out_invoice', 'out_refund'))]</field>
<field name="context">{'move_type':'out_invoice', 'journal_type': 'sale','readonly_by_pass': True}</field>
<field name="search_view_id" ref="account.view_account_invoice_filter"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create a customer invoice.
</p>
<p>
Odoo's electronic invoicing allows to ease and fasten the
collection of customer payments. Your customer receives the
invoice by email and he can pay online and/or import it
in his own system.
</p>
<p>
The discussions with your customer are automatically displayed at
the bottom of each invoice.
</p>
</field>
</record>
<record id="inherit_invoice_form" model="ir.ui.view">
<field name="name">inherit.invoice.form</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='tax_totals']" position="after">
<field name="amount_untaxed" widget='monetary'
options="{'currency_field': 'currency_id'}"/>
<field name="amount_tax" widget='monetary'
options="{'currency_field': 'currency_id'}"/>
<field name="discount_type" required="1"
attrs="{'invisible': [('amount_untaxed', '=', 0.00)], 'readonly': [('state', '!=', 'draft')]}"/>

<field name="discount_percentage" widget='monetary'
options="{'currency_field': 'currency_id'}"
attrs="{'readonly': ['|',('state', '!=', 'draft'),('discount_type', '=', 'fixed')],'invisible': [('discount_type', 'in', ('fixed','none'))]}"/>

<field name="discount" widget='monetary'
options="{'currency_field': 'currency_id'}"
attrs="{'readonly': ['|',('state', '!=', 'draft'),('discount_type', '=', 'percentage')],'invisible': [('discount_type', 'in', ('none'))]}"/>

<field name="disc_acc_id"
attrs="{'readonly': [('state', '!=', 'draft')],'required': [('discount', '!=', 0.0)],'invisible': ['|', ('discount_type', '=', 'none'),('discount', '=', 0.0)]}"/>

<field name="round_off_amount" widget='monetary' attrs="{'readonly': [('state', '!=', 'draft')]}"
options="{'currency_field': 'currency_id'}"/>

<div class="oe_subtotal_footer_separator oe_inline o_td_label">
<label for="invoice_total"/>
</div>
<field name="invoice_total" nolabel="1" class="oe_subtotal_footer_separator" widget='monetary'
options="{'currency_field': 'currency_id'}"/>
</xpath>
</field>
</record>
<record id="inherit_view_invoice_tree_bahmni" model="ir.ui.view">
<field name="name">Invoice View Changes</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_invoice_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<field name="partner_id"/>
</xpath>
<xpath expr="//field[@name='payment_state']" position="before">
<field name="invoice_total" sum="Total" optional="show"/>
<field name="amount_residual" sum="Total" optional="show"/>
</xpath>
</field>
</record>
<record id="account.action_move_out_invoice_type" model="ir.actions.act_window">
<field name="name">Customer Invoices</field>
<field name="res_model">account.move</field>
<field name="view_mode">tree,kanban,form,pivot,graph</field>
<field eval="False" name="view_id"/>
<field name="domain">[('move_type','in',('out_invoice', 'out_refund'))]</field>
<field name="context">{'move_type':'out_invoice', 'journal_type': 'sale','readonly_by_pass': True}</field>
<field name="search_view_id" ref="account.view_account_invoice_filter"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create a customer invoice.
</p>
<p>
Odoo's electronic invoicing allows to ease and fasten the
collection of customer payments. Your customer receives the
invoice by email and he can pay online and/or import it
in his own system.
</p>
<p>
The discussions with your customer are automatically displayed at
the bottom of each invoice.
</p>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions bahmni_auto_payment_reconciliation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions bahmni_auto_payment_reconciliation/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## This module developed by KGISL

{
"name": "Bahmni Auto Payment Reconciliation",
"summary": """This module extends the Customer payment functionality to allocate the payment amount automatically across multiple open invoices """,
"author": "Karthikeyan",
"website": "https://www.bahmni.org/",
"category": "Accounting",
"license": "LGPL-3",
"depends": ["account","bahmni_sale"],
"data": [
"security/ir.model.access.csv",
'views/account_payment_view_inherit.xml',
'views/res_config_inherit.xml',
'views/account_report.xml',
'report/report_invoice_inherit.xml',
],
"installable": True,
"application": True,
"auto_install": False,
}
2 changes: 2 additions & 0 deletions bahmni_auto_payment_reconciliation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_payment
from . import res_config_settings
Loading

0 comments on commit 7b4fc83

Please sign in to comment.