Browse Source

Merge pull request #367 from Tecnativa/9.0-partner_payment_return_risk

[9.0][ADD] partner_payment_return_risk: New module
pull/430/head
Rafael Blasco 8 years ago
committed by GitHub
parent
commit
92265d07d6
  1. 1
      oca_dependencies.txt
  2. 66
      partner_payment_return_risk/README.rst
  3. 3
      partner_payment_return_risk/__init__.py
  4. 19
      partner_payment_return_risk/__openerp__.py
  5. 53
      partner_payment_return_risk/i18n/es.po
  6. 3
      partner_payment_return_risk/models/__init__.py
  7. 39
      partner_payment_return_risk/models/res_partner.py
  8. 5
      partner_payment_return_risk/tests/__init__.py
  9. 38
      partner_payment_return_risk/tests/test_payment_return_risk.py
  10. 20
      partner_payment_return_risk/views/res_partner_view.xml

1
oca_dependencies.txt

@ -1 +1,2 @@
account-payment
product-attribute

66
partner_payment_return_risk/README.rst

@ -0,0 +1,66 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
===========================
Partner Payment Return Risk
===========================
Extends Partner Financial Risk to manage payments returns.
If any limit is exceed the partner gets forbidden to confirm sale orders.
Usage
=====
To use this module, you need to:
#. Go to *Customers > Financial Risk*
#. Set limits and choose options to compute in credit limit.
#. Create an invoice and pay it.
#. Create a payment return.
#. Go to *Sales -> Sales Orders* and create a new Sales Orders.
.. 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
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/partner-contact/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Carlos Dauden - Tecnativa <carlos.dauden@tecnativa.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

3
partner_payment_return_risk/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import models

19
partner_payment_return_risk/__openerp__.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden - Tecnativa <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Partner Payment Return Risk',
'version': '9.0.1.0.0',
'author': 'Tecnativa, '
'Odoo Community Association (OCA)',
'category': 'Sales Management',
'license': 'AGPL-3',
'depends': [
'partner_financial_risk',
'account_payment_return',
],
'data': [
'views/res_partner_view.xml',
],
'installable': True,
}

53
partner_payment_return_risk/i18n/es.po

@ -0,0 +1,53 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_payment_return_risk
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-01-10 18:34+0100\n"
"PO-Revision-Date: 2017-01-10 18:40+0100\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.8.7.1\n"
"Last-Translator: Carlos Dauden <carlos.dauden@tecnativa.com>\n"
"Language: es_ES\n"
#. module: partner_payment_return_risk
#: model:ir.model.fields,help:partner_payment_return_risk.field_res_partner_risk_payment_return_include
msgid "Full risk computation"
msgstr "Cálculo de riesgo completo"
#. module: partner_payment_return_risk
#: model:ir.model.fields,field_description:partner_payment_return_risk.field_res_partner_risk_payment_return_include
msgid "Include Payments Returns"
msgstr "Incluir pagos devueltos"
#. module: partner_payment_return_risk
#: model:ir.model.fields,field_description:partner_payment_return_risk.field_res_partner_risk_payment_return_limit
msgid "Limit Payments Returns"
msgstr "Límite en pagos devueltos"
#. module: partner_payment_return_risk
#: model:ir.model,name:partner_payment_return_risk.model_res_partner
msgid "Partner"
msgstr "Empresa"
#. module: partner_payment_return_risk
#: model:ir.model.fields,help:partner_payment_return_risk.field_res_partner_risk_payment_return_limit
msgid "Set 0 if it is not locked"
msgstr "Establece 0 si no está bloqueado"
#. module: partner_payment_return_risk
#: model:ir.model.fields,field_description:partner_payment_return_risk.field_res_partner_risk_payment_return
msgid "Total Returned Invoices"
msgstr "Total facturas devueltas"
#. module: partner_payment_return_risk
#: model:ir.model.fields,help:partner_payment_return_risk.field_res_partner_risk_payment_return
msgid "Total returned invoices in Open state"
msgstr "Total facturas devueltas en estado abierto"

3
partner_payment_return_risk/models/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import res_partner

39
partner_payment_return_risk/models/res_partner.py

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# © 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
class ResPartner(models.Model):
_inherit = 'res.partner'
risk_payment_return_include = fields.Boolean(
string='Include Payments Returns', help='Full risk computation')
risk_payment_return_limit = fields.Monetary(
string='Limit Payments Returns', help='Set 0 if it is not locked')
risk_payment_return = fields.Monetary(
compute='_compute_risk_payment_return', store=True,
string='Total Returned Invoices',
help='Total returned invoices in Open state')
@api.multi
@api.depends('invoice_ids.state', 'invoice_ids.returned_payment')
def _compute_risk_payment_return(self):
AccountInvoice = self.env['account.invoice']
for partner in self:
partner.risk_payment_return = AccountInvoice.read_group(
[('partner_id', '=', partner.id),
('returned_payment', '=', True),
('state', '=', 'open'),
],
['residual'],
[]
)[0]['residual']
@api.model
def _risk_field_list(self):
res = super(ResPartner, self)._risk_field_list()
res.append(('risk_payment_return', 'risk_payment_return_limit',
'risk_payment_return_include'))
return res

5
partner_payment_return_risk/tests/__init__.py

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

38
partner_payment_return_risk/tests/test_payment_return_risk.py

@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp.tests import common
class TestPartnerPaymentReturnRisk(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestPartnerPaymentReturnRisk, cls).setUpClass()
cls.partner = cls.env['res.partner'].create({
'name': 'Test partner',
'risk_payment_return_include': True,
'risk_payment_return_limit': 50.0,
})
cls.user_type = cls.env.ref('account.data_account_type_revenue')
cls.invoice = cls.env['account.invoice'].create({
'partner_id': cls.partner.id,
'invoice_line_ids': [(0, 0, {
'name': 'Product Test',
'quantity': 1.0,
'uom_id': cls.env.ref('product.product_uom_unit').id,
'price_unit': 100.0,
'account_id': cls.env['account.account'].search([
('user_type_id', '=', cls.user_type.id)], limit=1).id,
})]
})
def test_payment_return_risk(self):
self.invoice.signal_workflow('invoice_open')
# Partner risk is zero because invoice is not returned
self.assertAlmostEqual(self.partner.risk_payment_return, 0.0)
# We simulate that the invoice is returned
self.invoice.returned_payment = True
# Partner risk has increased
self.assertAlmostEqual(self.partner.risk_payment_return, 100.0)

20
partner_payment_return_risk/views/res_partner_view.xml

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 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="model">res.partner</field>
<field name="inherit_id" ref="partner_financial_risk.res_partner_view_risk"/>
<field name="arch" type="xml">
<field name="risk_invoice_unpaid" position="after">
<field name="risk_payment_return_include"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
<field name="risk_payment_return" nolabel="1"/>
</field>
<field name="risk_invoice_unpaid_limit" position="after">
<field name="risk_payment_return_limit"
attrs="{'readonly': [('risk_allow_edit', '=', False)]}"/>
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save