Browse Source

[IMP] partner_financial_risk: Improve fields help.

pull/294/head
Carlos Incaser 9 years ago
parent
commit
678711dc97
  1. 29
      partner_financial_risk/models/res_partner.py
  2. 4
      partner_financial_risk/models/sale.py
  3. 4
      partner_financial_risk/tests/test_partner_financial_risk.py

29
partner_financial_risk/models/res_partner.py

@ -16,41 +16,50 @@ class ResPartner(models.Model):
string='Limit Sale Orders', help='Set 0 if it not lock') string='Limit Sale Orders', help='Set 0 if it not lock')
risk_sale_order = fields.Monetary( risk_sale_order = fields.Monetary(
compute='_compute_risk_sale_order', store=True, compute='_compute_risk_sale_order', store=True,
string='Sale Order Not Invoiced')
string='Sale Order Not Invoiced',
help='Total not invoiced of sale order in *Sale Order* state')
risk_invoice_draft_include = fields.Boolean( risk_invoice_draft_include = fields.Boolean(
string='Include Draft Invoices', help='Compute in total risk') string='Include Draft Invoices', help='Compute in total risk')
risk_invoice_draft_limit = fields.Monetary( risk_invoice_draft_limit = fields.Monetary(
string='Limit In Draft Invoices', help='Set 0 if it not lock') string='Limit In Draft Invoices', help='Set 0 if it not lock')
risk_invoice_draft = fields.Monetary( risk_invoice_draft = fields.Monetary(
compute='_compute_risk_invoice', store=True, compute='_compute_risk_invoice', store=True,
string='Not Validated Invoice')
string='Not Validated Invoice',
help='Total amount of invoices in Draft or Pro-forma state')
risk_invoice_open_include = fields.Boolean( risk_invoice_open_include = fields.Boolean(
string='Include Open Invoices', help='Compute in total risk') string='Include Open Invoices', help='Compute in total risk')
risk_invoice_open_limit = fields.Monetary( risk_invoice_open_limit = fields.Monetary(
string='Limit In Open Invoices', help='Set 0 if it not lock') string='Limit In Open Invoices', help='Set 0 if it not lock')
risk_invoice_open = fields.Monetary( risk_invoice_open = fields.Monetary(
compute='_compute_risk_invoice', store=True, compute='_compute_risk_invoice', store=True,
string='Open Invoice')
string='Open Invoice',
help='Residual amount of invoices in Open state and the date due is '
'not exceeded, considering Maturity Margin set in account '
'settings')
risk_invoice_unpaid_include = fields.Boolean( risk_invoice_unpaid_include = fields.Boolean(
string='Include Unpaid Invoices', help='Compute in total risk') string='Include Unpaid Invoices', help='Compute in total risk')
risk_invoice_unpaid_limit = fields.Monetary( risk_invoice_unpaid_limit = fields.Monetary(
string='Limit In Unpaid Invoices', help='Set 0 if it not lock') string='Limit In Unpaid Invoices', help='Set 0 if it not lock')
risk_invoice_unpaid = fields.Monetary( risk_invoice_unpaid = fields.Monetary(
compute='_compute_risk_invoice', store=True, compute='_compute_risk_invoice', store=True,
string='Unpaid Invoice')
string='Unpaid Invoice',
help='Residual amount of invoices in Open state and the date due is '
'exceeded, considering Maturity Margin set in account settings')
risk_account_amount_include = fields.Boolean( risk_account_amount_include = fields.Boolean(
string='Include Other Account Amount', help='Compute in total risk') string='Include Other Account Amount', help='Compute in total risk')
risk_account_amount_limit = fields.Monetary( risk_account_amount_limit = fields.Monetary(
string='Limit Other Account Amount', help='Set 0 if it not lock') string='Limit Other Account Amount', help='Set 0 if it not lock')
risk_account_amount = fields.Monetary( risk_account_amount = fields.Monetary(
compute='_compute_risk_account_amount', compute='_compute_risk_account_amount',
string='Other Account Amount')
string='Other Account Amount',
help='Difference between accounting credit and rest of totals')
risk_total = fields.Monetary( risk_total = fields.Monetary(
string='Total Risk', compute='_compute_risk_exception')
risk_exception = fields.Boolean(compute='_compute_risk_exception')
compute='_compute_risk_exception',
string='Total Risk', help='Sum of total risk included')
risk_exception = fields.Boolean(
compute='_compute_risk_exception',
string='Risk Exception',
help='It Indicate if partner risk exceeded')
@api.multi @api.multi
@api.depends('sale_order_ids', 'sale_order_ids.invoice_pending_amount') @api.depends('sale_order_ids', 'sale_order_ids.invoice_pending_amount')

4
partner_financial_risk/models/sale.py

@ -26,14 +26,14 @@ class SaleOrder(models.Model):
def action_confirm(self): def action_confirm(self):
partner = self.partner_id partner = self.partner_id
if partner.risk_exception: if partner.risk_exception:
raise exceptions.Warning(_(
raise exceptions.UserError(_(
"Financial risk exceeded.\n" "Financial risk exceeded.\n"
"You can not confirm this sale order" "You can not confirm this sale order"
)) ))
elif partner.risk_sale_order_include and ( elif partner.risk_sale_order_include and (
(partner.risk_total + self.amount_total) > (partner.risk_total + self.amount_total) >
partner.credit_limit): partner.credit_limit):
raise exceptions.Warning(_(
raise exceptions.UserError(_(
"This sale order exceeds the financial risk.\n" "This sale order exceeds the financial risk.\n"
"You can not confirm this sale order" "You can not confirm this sale order"
)) ))

4
partner_financial_risk/tests/test_partner_financial_risk.py

@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import fields from openerp import fields
from openerp.exceptions import Warning
from openerp.exceptions import UserError
from openerp.tests.common import TransactionCase from openerp.tests.common import TransactionCase
@ -74,5 +74,5 @@ class TestPartnerFinancialRisk(TransactionCase):
self.partner.risk_invoice_unpaid_include = True self.partner.risk_invoice_unpaid_include = True
self.assertAlmostEqual(self.partner.risk_total, 500.0) self.assertAlmostEqual(self.partner.risk_total, 500.0)
self.partner.risk_total = 100.0 self.partner.risk_total = 100.0
with self.assertRaises(Warning):
with self.assertRaises(UserError):
self.sale_order.action_confirm() self.sale_order.action_confirm()
Loading…
Cancel
Save