Browse Source

Backport to 8.0

pull/361/head
Andhitia Rama 8 years ago
parent
commit
bd6c2b94bc
  1. 5
      partner_financial_risk/README.rst
  2. 2
      partner_financial_risk/__init__.py
  3. 7
      partner_financial_risk/__openerp__.py
  4. 28
      partner_financial_risk/data/partner_financial_risk_data.xml
  5. 2
      partner_financial_risk/models/__init__.py
  6. 2
      partner_financial_risk/models/account_invoice.py
  7. 2
      partner_financial_risk/models/res_company.py
  8. 2
      partner_financial_risk/models/res_config.py
  9. 20
      partner_financial_risk/models/res_partner.py
  10. 2
      partner_financial_risk/tests/__init__.py
  11. 18
      partner_financial_risk/tests/test_partner_financial_risk.py
  12. 28
      partner_financial_risk/views/account_invoice_view.xml
  13. 38
      partner_financial_risk/views/res_config_view.xml
  14. 106
      partner_financial_risk/views/res_partner_view.xml
  15. 2
      partner_financial_risk/wizard/__init__.py
  16. 2
      partner_financial_risk/wizard/parner_risk_exceeded.py
  17. 58
      partner_financial_risk/wizard/partner_risk_exceeded_view.xml

5
partner_financial_risk/README.rst

@ -16,7 +16,7 @@ Configuration
To configure this module, you need to:
#. Go to *Invoicing/Accounting > Configuration > Settings > Invoicing & Payments*
#. Go to *Settings > Configuration > Invoicing*
#. In the *Financial Risk* section, fill *Unpaid Margin* for setting the number
of days to last after the due date to consider an invoice as unpaid.
@ -36,7 +36,7 @@ To use this module, you need to:
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/134/9.0
:target: https://runbot.odoo-community.org/runbot/134/8.0
Bug Tracker
@ -56,6 +56,7 @@ Contributors
* Carlos Dauden <carlos.dauden@tecnativa.com>
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
* OpenSynergy Indonesia <https://opensynergy-indonesia.com>
Maintainer

2
partner_financial_risk/__init__.py

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models
from . import wizard

7
partner_financial_risk/__openerp__.py

@ -1,14 +1,15 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Partner Financial Risk',
'summary': 'Manage partner risk',
'version': '9.0.1.0.0',
'version': '8.0.1.0.0',
'category': 'Sales Management',
'license': 'AGPL-3',
'author': 'Tecnativa, Odoo Community Association (OCA)',
'author': 'Tecnativa, '
'Odoo Community Association (OCA)',
'website': 'https://www.tecnativa.com',
'depends': ['account'],
'data': [

28
partner_financial_risk/data/partner_financial_risk_data.xml

@ -1,15 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
<!-- Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3). -->
<odoo>
<record id="ir_cron_due_invoice_every_day" model="ir.cron">
<field name="name">Financial risk: Process due invoices</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model" eval="'res.partner'"/>
<field name="function" eval="'process_unpaid_invoices'"/>
<field name="args" eval="'()'"/>
</record>
</odoo>
<openerp>
<data>
<record id="ir_cron_due_invoice_every_day" model="ir.cron">
<field name="name">Financial risk: Process due invoices</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model" eval="'res.partner'"/>
<field name="function" eval="'process_unpaid_invoices'"/>
<field name="args" eval="'()'"/>
</record>
</data>
</openerp>

2
partner_financial_risk/models/__init__.py

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import account_invoice
from . import res_company

2
partner_financial_risk/models/account_invoice.py

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import api, models, _

2
partner_financial_risk/models/res_company.py

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import fields, models

2
partner_financial_risk/models/res_config.py

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import fields, models

20
partner_financial_risk/models/res_partner.py

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from datetime import datetime
@ -12,17 +12,17 @@ class ResPartner(models.Model):
risk_invoice_draft_include = fields.Boolean(
string='Include Draft Invoices', help='Full risk computation')
risk_invoice_draft_limit = fields.Monetary(
risk_invoice_draft_limit = fields.Float(
string='Limit In Draft Invoices', help='Set 0 if it is not locked')
risk_invoice_draft = fields.Monetary(
risk_invoice_draft = fields.Float(
compute='_compute_risk_invoice', store=True,
string='Total Draft Invoices',
help='Total amount of invoices in Draft or Pro-forma state')
risk_invoice_open_include = fields.Boolean(
string='Include Open Invoices', help='Full risk computation')
risk_invoice_open_limit = fields.Monetary(
risk_invoice_open_limit = fields.Float(
string='Limit In Open Invoices', help='Set 0 if it is not locked')
risk_invoice_open = fields.Monetary(
risk_invoice_open = fields.Float(
compute='_compute_risk_invoice', store=True,
string='Total Open Invoices',
help='Residual amount of invoices in Open state and the date due is '
@ -30,9 +30,9 @@ class ResPartner(models.Model):
'settings')
risk_invoice_unpaid_include = fields.Boolean(
string='Include Unpaid Invoices', help='Full risk computation')
risk_invoice_unpaid_limit = fields.Monetary(
risk_invoice_unpaid_limit = fields.Float(
string='Limit In Unpaid Invoices', help='Set 0 if it is not locked')
risk_invoice_unpaid = fields.Monetary(
risk_invoice_unpaid = fields.Float(
compute='_compute_risk_invoice', store=True,
string='Total Unpaid Invoices',
help='Residual amount of invoices in Open state and the date due is '
@ -40,14 +40,14 @@ class ResPartner(models.Model):
risk_account_amount_include = fields.Boolean(
string='Include Other Account Amount', help='Full risk computation')
risk_account_amount_limit = fields.Monetary(
risk_account_amount_limit = fields.Float(
string='Limit Other Account Amount', help='Set 0 if it is not locked')
risk_account_amount = fields.Monetary(
risk_account_amount = fields.Float(
compute='_compute_risk_account_amount',
string='Other Account Amount',
help='Difference between accounting credit and rest of totals')
risk_total = fields.Monetary(
risk_total = fields.Float(
compute='_compute_risk_exception',
string='Total Risk', help='Sum of total risk included')
risk_exception = fields.Boolean(

2
partner_financial_risk/tests/__init__.py

@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_partner_financial_risk

18
partner_financial_risk/tests/test_partner_financial_risk.py

@ -1,12 +1,15 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp.tests.common import TransactionCase
from openerp import fields
from dateutil.relativedelta import relativedelta
from datetime import datetime
class TestPartnerFinancialRisk(TransactionCase):
def setUp(self):
super(TestPartnerFinancialRisk, self).setUp()
self.env.user.groups_id |= self.env.ref('base.group_sale_manager')
@ -19,14 +22,19 @@ class TestPartnerFinancialRisk(TransactionCase):
'name': 'Test Sales',
'code': 'TSALE',
})
self.prod_account = self.env.ref('account.demo_coffee_machine_account')
self.inv_account = self.env.ref('account.demo_sale_of_land_account')
self.prod_account = self.env.ref('account.a_sale')
self.inv_account = self.env.ref('account.a_recv')
date_inv = datetime.now() - relativedelta(days=7)
date_due = datetime.now() - relativedelta(days=3)
self.invoice = self.env['account.invoice'].create({
'journal_id': self.journal.id,
'company_id': self.env.user.company_id.id,
'currency_id': self.env.user.company_id.currency_id.id,
'date_invoice': date_inv.strftime("%Y-%m-%d"),
'date_due': date_due.strftime("%Y-%m-%d"),
'partner_id': self.partner.id,
'invoice_line_ids': [(0, 0, {
'account_id': self.inv_account.id,
'invoice_line': [(0, 0, {
'account_id': self.prod_account.id,
'name': 'Test line',
'price_unit': 50,
@ -40,8 +48,8 @@ class TestPartnerFinancialRisk(TransactionCase):
self.assertAlmostEqual(self.partner.risk_total, 500.0)
self.invoice.signal_workflow('invoice_open')
self.assertAlmostEqual(self.partner.risk_invoice_draft, 0.0)
self.assertFalse(self.invoice.date_due)
self.partner.risk_invoice_unpaid_include = True
self.assertAlmostEqual(self.partner.risk_invoice_unpaid, 500.0)
self.assertAlmostEqual(self.partner.risk_total, 500.0)
self.partner.credit_limit = 100.0
self.assertTrue(self.partner.risk_exception)

28
partner_financial_risk/views/account_invoice_view.xml

@ -1,15 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
<!-- Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3). -->
<odoo>
<record id="invoice_partner_risk_form" model="ir.ui.view">
<field name="name">account.invoice.partner.risk.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<button name="invoice_open" position="attributes">
<attribute name="type">object</attribute>
</button>
</field>
</record>
</odoo>
<openerp>
<data>
<record id="invoice_partner_risk_form" model="ir.ui.view">
<field name="name">account.invoice.partner.risk.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<button name="invoice_open" position="attributes">
<attribute name="type">object</attribute>
</button>
</field>
</record>
</data>
</openerp>

38
partner_financial_risk/views/res_config_view.xml

@ -1,21 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
<!-- Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3). -->
<odoo>
<record id="view_account_config" model="ir.ui.view">
<field name="name">account settings</field>
<field name="model">account.config.settings</field>
<field name="inherit_id" ref="account.view_account_config_settings"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='payment_acquirer']/.." position="after">
<label for="id" string="Financial Risk"/>
<div name="financial_risk" string="Financial Risk div">
<label for="invoice_unpaid_margin"/>
<field name="invoice_unpaid_margin" class="oe_inline"/>
</div>
</xpath>
</field>
</record>
</odoo>
<openerp>
<data>
<record id="view_account_config" model="ir.ui.view">
<field name="name">account settings</field>
<field name="model">account.config.settings</field>
<field name="inherit_id" ref="account.view_account_config_settings"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='payment_acquirer']/.." position="after">
<label for="id" string="Financial Risk"/>
<div name="financial_risk" string="Financial Risk div">
<label for="invoice_unpaid_margin"/>
<field name="invoice_unpaid_margin" class="oe_inline"/>
</div>
</xpath>
</field>
</record>
</data>
</openerp>

106
partner_financial_risk/views/res_partner_view.xml

@ -1,58 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
<!-- Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3). -->
<odoo>
<record id="res_partner_view_risk" model="ir.ui.view">
<field name="name">res.partner.view.risk</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="priority" eval="20"/>
<field name="groups_id" eval="[(4, ref('base.group_sale_salesman')), (4, ref('account.group_account_manager'))]"/>
<field name="arch" type="xml">
<page name="sales_purchases" position="after">
<page name="financial_risk" string="Financial Risk" attrs="{'invisible': [('customer','=',False)]}">
<group name="risk_general" col="3">
<group string="General Limits" name="risk_include" col="1" colspan="2">
<group col="3" class="oe_subtotal_footer">
<field name="risk_invoice_draft_include"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_invoice_draft" nolabel="1"/>
<field name="risk_invoice_open_include"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_invoice_open" nolabel="1"/>
<field name="risk_invoice_unpaid_include"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_invoice_unpaid" nolabel="1"/>
<field name="risk_account_amount_include"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_account_amount" nolabel="1"/>
<field name="risk_total" colspan="3" class="oe_subtotal_footer_separator"/>
</group>
</group>
<group string="Specific Limits" name="risk_limits" col="1">
<group class="oe_subtotal_footer">
<field name="risk_invoice_draft_limit"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_invoice_open_limit"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_invoice_unpaid_limit"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_account_amount_limit"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_allow_edit" invisible="1"/>
</group>
<openerp>
<data>
<record id="res_partner_view_risk" model="ir.ui.view">
<field name="name">res.partner.view.risk</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="priority" eval="20"/>
<field name="groups_id" eval="[(4, ref('base.group_sale_salesman')), (4, ref('account.group_account_manager'))]"/>
<field name="arch" type="xml">
<page name="sales_purchases" position="after">
<page name="financial_risk" string="Financial Risk" attrs="{'invisible': [('customer','=',False)]}">
<group name="risk_general" col="3">
<group string="General Limits" name="risk_include" col="1" colspan="2">
<group col="3" class="oe_subtotal_footer">
<field name="risk_invoice_draft_include"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_invoice_draft" nolabel="1"/>
<field name="risk_invoice_open_include"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_invoice_open" nolabel="1"/>
<field name="risk_invoice_unpaid_include"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_invoice_unpaid" nolabel="1"/>
<field name="risk_account_amount_include"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_account_amount" nolabel="1"/>
<field name="risk_total" colspan="3" class="oe_subtotal_footer_separator"/>
</group>
</group>
<group string="Info" col="4">
<field name="credit_limit"
widget="monetary"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="credit_policy"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_exception"/>
<group string="Specific Limits" name="risk_limits" col="1">
<group class="oe_subtotal_footer">
<field name="risk_invoice_draft_limit"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_invoice_open_limit"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_invoice_unpaid_limit"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_account_amount_limit"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_allow_edit" invisible="1"/>
</group>
</group>
</page>
</group>
<group string="Info" col="4">
<field name="credit_limit"
widget="monetary"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="credit_policy"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_exception"/>
</group>
</page>
</field>
</record>
</odoo>
</page>
</field>
</record>
</data>
</openerp>

2
partner_financial_risk/wizard/__init__.py

@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import parner_risk_exceeded

2
partner_financial_risk/wizard/parner_risk_exceeded.py

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import api, fields, models, _

58
partner_financial_risk/wizard/partner_risk_exceeded_view.xml

@ -1,30 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
<!-- Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3). -->
<odoo>
<record id="partner_risk_exceeded_wizard" model="ir.ui.view">
<field name="name">Partner risk exceeded</field>
<field name="model">partner.risk.exceeded.wiz</field>
<field name="arch" type="xml">
<form string="Risk exceeded">
<p>The partner has exceeded his risk</p>
<field name="exception_msg" colspan="2" nolabel="1"/>
<group>
<field name="partner_id"/>
</group>
<footer>
<button string="Continue"
class="oe_highlight"
name="button_continue"
type="object"
groups="base.group_sale_manager,account.group_account_manager"
/>
<button string="Cancel"
class="oe_link"
special="cancel"
/>
</footer>
</form>
</field>
</record>
</odoo>
<openerp>
<data>
<record id="partner_risk_exceeded_wizard" model="ir.ui.view">
<field name="name">Partner risk exceeded</field>
<field name="model">partner.risk.exceeded.wiz</field>
<field name="arch" type="xml">
<form string="Risk exceeded">
<p>The partner has exceeded his risk</p>
<field name="exception_msg" colspan="2" nolabel="1"/>
<group>
<field name="partner_id"/>
</group>
<footer>
<button string="Continue"
class="oe_highlight"
name="button_continue"
type="object"
groups="base.group_sale_manager,account.group_account_manager"
/>
<button string="Cancel"
class="oe_link"
special="cancel"
/>
</footer>
</form>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save