Skip to content

Commit

Permalink
BAH-4141 | Add. Field to show billed amount before round off in retur…
Browse files Browse the repository at this point in the history
…n form (#200)
  • Loading branch information
mohan-13 authored Jan 29, 2025
1 parent 12ae8bb commit 1ca99fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 9 additions & 6 deletions bahmni_customer_return/models/bahmni_customer_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import timedelta, datetime
from odoo import models, fields, api, _
from odoo.exceptions import UserError
from odoo.tools.float_utils import float_round

RES_USERS = 'res.users'
TIME_FORMAT = '%Y-%m-%d %H:%M:%S'
Expand Down Expand Up @@ -38,6 +39,7 @@ class BahmniCustomerReturn(models.Model):
discount_value = fields.Float(string="Dicount Amount", store=True, compute='_compute_all_line')
return_amt = fields.Float(string="Return Amount", store=True, compute='_compute_all_line')
round_off_amount = fields.Float(string="Round Off Amount", store=True, compute='_compute_all_line')
billed_amount = fields.Float(string="Billed Amount", store=True, compute='_compute_all_line')
product_ids = fields.Many2many('product.product','customer_returns_products','return_id','product_id','Products',domain=[('active', '=', True)])


Expand Down Expand Up @@ -123,12 +125,13 @@ def _compute_all_line(self):
applied_discount_percentage = 0
line_discount_value = (line.sub_total * applied_discount_percentage) / 100
cumulative_discount_value += line_discount_value

data.discount_value = cumulative_discount_value
total_return_amount_without_discount = sum(line.sub_total for line in data.line_ids)
data.tot_amt = total_return_amount_without_discount - cumulative_discount_value
data.round_off_amount = self.env['rounding.off'].round_off_value_to_nearest(data.tot_amt)
data.return_amt = data.tot_amt + data.round_off_amount

prec = self.env['decimal.precision'].precision_get('Account')
data.discount_value = float_round(cumulative_discount_value, precision_digits=prec, rounding_method='HALF-UP')
data.tot_amt = float_round(sum(line.sub_total for line in data.line_ids), precision_digits=prec, rounding_method='HALF-UP')
data.billed_amount = data.tot_amt - data.discount_value
data.round_off_amount = self.env['rounding.off'].round_off_value_to_nearest(data.billed_amount)
data.return_amt = data.billed_amount + data.round_off_amount


def display_warnings(self, warning_msg, kw):
Expand Down
2 changes: 2 additions & 0 deletions bahmni_customer_return/views/bahmni_customer_return_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
options="{'currency_field': 'currency_id'}"/>
<field name="discount_value" widget='monetary' readonly = "1" force_save="1"
options="{'currency_field': 'currency_id'}"/>
<field name="billed_amount" widget='monetary' readonly = "1" force_save="1"
options="{'currency_field': 'currency_id'}"/>
<field name="round_off_amount" widget='monetary' readonly = "1" force_save="1"
options="{'currency_field': 'currency_id'}"/>
<field name="return_amt" widget='monetary' readonly = "1" force_save="1"
Expand Down

0 comments on commit 1ca99fd

Please sign in to comment.