mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[IMP] sale_credit_limit: forward port improvements, Hibou Professional
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
{
|
||||
'name': 'Sale Credit 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.",
|
||||
'category': 'Sale',
|
||||
'license': 'AGPL-3',
|
||||
'license': 'OPL-1',
|
||||
'complexity': 'expert',
|
||||
'images': [],
|
||||
'website': "https://hibou.io",
|
||||
|
||||
@@ -16,4 +16,32 @@ if partner.credit_limit and partner.credit_limit <= partner_balance:
|
||||
<field name="active" eval="True" />
|
||||
</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) < str(datetime.date.today())) and i.move_type == 'out_invoice'):
|
||||
failed = True
|
||||
</field>
|
||||
<field name="active" eval="True" />
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -1 +1,4 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from . import partner
|
||||
from . import sale
|
||||
|
||||
18
sale_credit_limit/models/partner.py
Normal file
18
sale_credit_limit/models/partner.py
Normal 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
|
||||
@@ -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.tools.safe_eval import datetime as wrapped_datetime
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_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')
|
||||
def _onchange_partner_invoice_id(self):
|
||||
for so in self:
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from . import test_sale_credit_exception
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -8,10 +9,7 @@ class TestSaleCreditException(TestSaleException):
|
||||
super(TestSaleCreditException, self).setUp()
|
||||
|
||||
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']
|
||||
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.credit_limit = 100.00
|
||||
p = self.env.ref('product.product_product_25_product_template')
|
||||
|
||||
@@ -6,8 +6,13 @@
|
||||
<field name="model">res.partner</field>
|
||||
<field name="inherit_id" ref="base.view_partner_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='accounting_entries']" position="inside">
|
||||
<field name="credit_limit" widget="monetary" attrs="{'invisible': [('parent_id', '!=', False)]}"/>
|
||||
<xpath expr="//group[@name='accounting_entries']" position="after">
|
||||
<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>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user