Skip to content

Commit

Permalink
[MIG]sale_exception_credit_limit: with constrains
Browse files Browse the repository at this point in the history
  • Loading branch information
jok-adhoc committed Jan 18, 2023
1 parent fb79fed commit a39a138
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
20 changes: 11 additions & 9 deletions sale_exception_credit_limit/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@
# directory
##############################################################################
from odoo import models, fields, api
from odoo.exceptions import ValidationError



class ResPartner(models.Model):
_inherit = "res.partner"

credit_sale_exception = fields.Monetary(compute='_compute_credit_sale_exception',
string='Total Receivable', help="Total amount this customer owes you (including not invoiced sale orders).",
credit_with_confirmed_orders = fields.Monetary(compute='_compute_credit_with_confirmed_orders',
string='Total Receivable', help="Total amount this customer owes you (including not invoiced confirmed sale orders and draft invoices).",
groups='account.group_account_invoice,account.group_account_readonly'
)

@api.constrains('credit_limit', 'use_partner_credit_limit')
def check_credit_limit_edition(self):
# TODO verificar cual es el metodo has_group / has_groups que mas se usa
if not self.env.user.has_groups(''):
raise Warnin
def check_credit_limit_group(self):
if not self.env.user.has_group('sale_exception_credit_limit.credit_config'):
raise ValidationError('People without Credit limit Configuration Rights cannot modify credit limit parameters')

@api.depends_context('company')
def _compute_credit_sale_exception(self):
def _compute_credit_with_confirmed_orders(self):
# Sets 0 when use_partner_credit_limit is not set avoiding unnecessary overloads
if not self.use_partner_credit_limit:
self.credit_sale_exception = 0
self.credit_with_confirmed_orders = 0
else:
domain = [
('order_id.partner_id.commercial_partner_id', '=', self.commercial_partner_id.id),
Expand Down Expand Up @@ -77,5 +79,5 @@ def _compute_credit_sale_exception(self):



self.credit_sale_exception = to_invoice_amount + draft_invoice_lines_amount + self.credit
self.credit_with_confirmed_orders = to_invoice_amount + draft_invoice_lines_amount + self.credit

3 changes: 1 addition & 2 deletions sale_exception_credit_limit/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# directory
##############################################################################
from odoo import models, fields, api
from odoo.tools.float_utils import float_is_zero


class SaleOrder(models.Model):
Expand All @@ -17,7 +16,7 @@ def _compute_partner_credit_warning(self):
show_warning = order.state in ('draft', 'sent') and \
order.company_id.account_use_credit_limit
if show_warning:
updated_credit = order.partner_id.commercial_partner_id.credit_sale_exception + (order.amount_total * order.currency_rate)
updated_credit = order.partner_id.commercial_partner_id.credit_with_confirmed_orders + (order.amount_total * order.currency_rate)
order.partner_credit_warning = self.env['account.move']._build_credit_warning_message(
order, updated_credit)

Expand Down
2 changes: 1 addition & 1 deletion sale_exception_credit_limit/views/res_partner_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<attribute name="invisible">1</attribute>
</field>
<field name="credit" position="after">
<field name="credit_sale_exception"/>
<field name="credit_with_confirmed_orders" attrs="{'invisible': [('use_partner_credit_limit', '=', False)]}"/>
</field>
</field>
</record>
Expand Down

0 comments on commit a39a138

Please sign in to comment.