diff --git a/sale_credit_limit/__manifest__.py b/sale_credit_limit/__manifest__.py
index 8b45f97c..f5c0bae1 100644
--- a/sale_credit_limit/__manifest__.py
+++ b/sale_credit_limit/__manifest__.py
@@ -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",
diff --git a/sale_credit_limit/data/sale_exceptions.xml b/sale_credit_limit/data/sale_exceptions.xml
index b8f6192d..796e107f 100644
--- a/sale_credit_limit/data/sale_exceptions.xml
+++ b/sale_credit_limit/data/sale_exceptions.xml
@@ -16,4 +16,32 @@ if partner.credit_limit and partner.credit_limit <= partner_balance:
+
+ Customer On Credit Hold.
+ The Customer is on Credit Hold.
+ Please have the customer contact accounting.
+ 50
+ sale.order
+
+partner = sale.partner_invoice_id.commercial_partner_id
+if partner.credit_hold:
+ failed = True
+
+
+
+
+
+ Customer has Overdue Invoices.
+ The Customer has unpaid overdue invoices.
+ Please have the customer contact accounting.
+ 55
+ sale.order
+
+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
+
+
+
+
\ No newline at end of file
diff --git a/sale_credit_limit/models/__init__.py b/sale_credit_limit/models/__init__.py
index 8a0dc04e..da805931 100644
--- a/sale_credit_limit/models/__init__.py
+++ b/sale_credit_limit/models/__init__.py
@@ -1 +1,4 @@
+# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
+
+from . import partner
from . import sale
diff --git a/sale_credit_limit/models/partner.py b/sale_credit_limit/models/partner.py
new file mode 100644
index 00000000..ce018f0f
--- /dev/null
+++ b/sale_credit_limit/models/partner.py
@@ -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
diff --git a/sale_credit_limit/models/sale.py b/sale_credit_limit/models/sale.py
index 5b90514e..4512fcac 100644
--- a/sale_credit_limit/models/sale.py
+++ b/sale_credit_limit/models/sale.py
@@ -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:
diff --git a/sale_credit_limit/tests/__init__.py b/sale_credit_limit/tests/__init__.py
index a2d422d0..2fe6104a 100644
--- a/sale_credit_limit/tests/__init__.py
+++ b/sale_credit_limit/tests/__init__.py
@@ -1 +1,3 @@
+# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
+
from . import test_sale_credit_exception
diff --git a/sale_credit_limit/tests/test_sale_credit_exception.py b/sale_credit_limit/tests/test_sale_credit_exception.py
index 01a63cfd..f0af5e30 100644
--- a/sale_credit_limit/tests/test_sale_credit_exception.py
+++ b/sale_credit_limit/tests/test_sale_credit_exception.py
@@ -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')
diff --git a/sale_credit_limit/views/partner_views.xml b/sale_credit_limit/views/partner_views.xml
index e9dbe0ae..7463769c 100644
--- a/sale_credit_limit/views/partner_views.xml
+++ b/sale_credit_limit/views/partner_views.xml
@@ -6,8 +6,13 @@
res.partner
-
-
+
+
+
+
+
+
+