[IMP] sale_credit_limit: forward port improvements, Hibou Professional

This commit is contained in:
Jared Kipe
2021-03-22 15:16:19 -07:00
parent f1d694cb34
commit 7aa422f738
8 changed files with 71 additions and 7 deletions

View File

@@ -1,10 +1,10 @@
{ {
'name': 'Sale Credit Limit', 'name': 'Sale Credit Limit',
'summary': 'Uses credit limit on Partners to warn salespeople if they are over their limit.', 'summary': 'Uses credit limit on Partners to warn salespeople if they are over their limit.',
'version': '14.0.1.0.0', 'version': '14.0.1.0.1',
'author': "Hibou Corp.", 'author': "Hibou Corp.",
'category': 'Sale', 'category': 'Sale',
'license': 'AGPL-3', 'license': 'OPL-1',
'complexity': 'expert', 'complexity': 'expert',
'images': [], 'images': [],
'website': "https://hibou.io", 'website': "https://hibou.io",

View File

@@ -16,4 +16,32 @@ if partner.credit_limit and partner.credit_limit <= partner_balance:
<field name="active" eval="True" /> <field name="active" eval="True" />
</record> </record>
<record id="excep_sale_credit_hold" model="exception.rule">
<field name="name">Customer On Credit Hold.</field>
<field name="description">The Customer is on Credit Hold.
Please have the customer contact accounting.</field>
<field name="sequence">50</field>
<field name="model">sale.order</field>
<field name="code">
partner = sale.partner_invoice_id.commercial_partner_id
if partner.credit_hold:
failed = True
</field>
<field name="active" eval="True" />
</record>
<record id="excep_invoice_overdue" model="exception.rule">
<field name="name">Customer has Overdue Invoices.</field>
<field name="description">The Customer has unpaid overdue invoices.
Please have the customer contact accounting.</field>
<field name="sequence">55</field>
<field name="model">sale.order</field>
<field name="code">
partner = sale.partner_invoice_id.commercial_partner_id
if partner.invoice_ids.filtered(lambda i: i.state == 'posted' and i.payment_state != 'paid' and (i.invoice_date_due and str(i.invoice_date_due) &lt; str(datetime.date.today())) and i.move_type == 'out_invoice'):
failed = True
</field>
<field name="active" eval="True" />
</record>
</odoo> </odoo>

View File

@@ -1 +1,4 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from . import partner
from . import sale from . import sale

View File

@@ -0,0 +1,18 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from odoo import api, fields, models
class ResPartner(models.Model):
_inherit = 'res.partner'
credit_remaining = fields.Float('Credit Remaining', compute='_compute_credit_remaining')
credit_hold = fields.Boolean('Credit Hold')
@api.depends('credit_limit', 'credit')
def _compute_credit_remaining(self):
for partner in self:
if partner.credit_limit:
partner.credit_remaining = partner.credit_limit - partner.credit
else:
partner.credit_remaining = 0.0

View File

@@ -1,9 +1,19 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from odoo import api, models, tools from odoo import api, models, tools
from odoo.tools.safe_eval import datetime as wrapped_datetime
class SaleOrder(models.Model): class SaleOrder(models.Model):
_inherit = 'sale.order' _inherit = 'sale.order'
# We need a way to be able to create a 'today' date to compare
@api.model
def _exception_rule_eval_context(self, rec):
res = super(SaleOrder, self)._exception_rule_eval_context(rec)
res["datetime"] = wrapped_datetime
return res
@api.onchange('partner_invoice_id') @api.onchange('partner_invoice_id')
def _onchange_partner_invoice_id(self): def _onchange_partner_invoice_id(self):
for so in self: for so in self:

View File

@@ -1 +1,3 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from . import test_sale_credit_exception from . import test_sale_credit_exception

View File

@@ -1,3 +1,4 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from odoo.addons.sale_exception.tests.test_sale_exception import TestSaleException from odoo.addons.sale_exception.tests.test_sale_exception import TestSaleException
@@ -8,10 +9,7 @@ class TestSaleCreditException(TestSaleException):
super(TestSaleCreditException, self).setUp() super(TestSaleCreditException, self).setUp()
def test_sale_order_credit_limit_exception(self): def test_sale_order_credit_limit_exception(self):
admin_user = self.env.ref('base.user_admin')
self.sale_exception_confirm = self.env['sale.exception.confirm'] self.sale_exception_confirm = self.env['sale.exception.confirm']
exception = self.env.ref('sale_credit_limit.excep_sale_credit_limit').with_user(admin_user)
exception.active = True
partner = self.env.ref('base.res_partner_12') partner = self.env.ref('base.res_partner_12')
partner.credit_limit = 100.00 partner.credit_limit = 100.00
p = self.env.ref('product.product_product_25_product_template') p = self.env.ref('product.product_product_25_product_template')

View File

@@ -6,8 +6,13 @@
<field name="model">res.partner</field> <field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/> <field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//group[@name='accounting_entries']" position="inside"> <xpath expr="//group[@name='accounting_entries']" position="after">
<field name="credit_limit" widget="monetary" attrs="{'invisible': [('parent_id', '!=', False)]}"/> <group string="Credit Limit" name="credit_limit" groups="account.group_account_invoice">
<field name="credit" widget="monetary" attrs="{'invisible': [('parent_id', '!=', False)]}" />
<field name="credit_limit" attrs="{'invisible': [('parent_id', '!=', False)]}" />
<field name="credit_remaining" widget="monetary" attrs="{'invisible': [('parent_id', '!=', False)]}" />
<field name="credit_hold" attrs="{'invisible': [('parent_id', '!=', False)]}" />
</group>
</xpath> </xpath>
</field> </field>
</record> </record>