Skip to content

Commit

Permalink
[16.0][MIG] account_credit_control
Browse files Browse the repository at this point in the history
  • Loading branch information
astirpe committed Mar 7, 2023
1 parent ebb81aa commit 4032416
Show file tree
Hide file tree
Showing 16 changed files with 188 additions and 157 deletions.
2 changes: 1 addition & 1 deletion account_credit_control/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Account Credit Control",
"version": "15.0.1.2.0",
"version": "16.0.1.0.0",
"author": "Camptocamp,"
"Odoo Community Association (OCA),"
"Okia,"
Expand Down
191 changes: 94 additions & 97 deletions account_credit_control/data/data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
<!--Email template -->
<record id="email_template_credit_control_base" model="mail.template">
<field name="name">Credit Control Email</field>
<field name="email_from">${user.company_id.email or ''}</field>
<field name="email_from">{{user.company_id.email or ''}}</field>
<field
name="subject"
>Credit Control: (${object.policy_level_id.name or 'n/a'})</field>
<field name="partner_to">${object.get_emailing_contact().id or ''}</field>
>Credit Control: ({{object.policy_level_id.name or 'n/a'}})</field>
<field name="partner_to">{{object.get_emailing_contact().id or ''}}</field>
<field name="model_id" ref="model_credit_control_communication" />
<field name="auto_delete" eval="False" />
<field name="lang">${object.contact_address_id.lang or 'en_US'}</field>
<field name="lang">{{object.contact_address_id.lang or 'en_US'}}</field>
<field name="report_template" ref="credit_control_summary" />
<field
name="body_html"
><![CDATA[
Dear ${object.contact_address_id.name or ''}
<br/>
<br/>
${object.policy_level_id.custom_mail_text | safe}
]]></field>
<field name="body_html" type="html">
<p>Dear <t t-out="object.contact_address_id.name or '' " />,</p>
<br />
<br />
<p><t t-out="object.policy_level_id.custom_mail_text or '' " /></p>
</field>
</record>
<!-- policy no follow -->
<record model="credit.control.policy" id="credit_control_no_follow">
Expand Down Expand Up @@ -53,24 +51,23 @@
<field
name="custom_text"
>Our records indicate that we have not received the payment of the invoice mentioned below.
If it has already been sent, please disregard this notice. If not, please proceed with payment within 10 days.
If it has already been sent, please disregard this notice. If not, please proceed with payment within 10 days.

Thank you in advance for your anticipated cooperation in this matter.
Thank you in advance for your anticipated cooperation in this matter.

Best regards
Best regards
</field>
<field name="mail_show_invoice_detail" eval="True" />
<field
name="custom_mail_text"
><![CDATA[
Our records indicate that we have not received the payment of the invoices mentioned in the attached document.<br/>
<br/>
If it has already been sent, please disregard this notice. If not, please proceed with payment within 10 days.<br/>
<br/>
Thank you in advance for your anticipated cooperation in this matter.<br/>
<br/>
Best regards
]]></field>
<field name="custom_mail_text" type="html">
<p
>Our records indicate that we have not received the payment of the invoices mentioned in the attached document.
<br />
If it has already been sent, please disregard this notice. If not, please proceed with payment within 10 days.</p>
<br />
<p>Thank you in advance for your anticipated cooperation in this matter.</p>
<br />
<p>Best regards</p>
</field>
</record>
<record model="credit.control.policy.level" id="3_time_2">
<field name="name">30 days end of month</field>
Expand All @@ -83,23 +80,23 @@
<field
name="custom_text"
>Our records indicate that we have not yet received the payment of the invoice mentioned below despite our first reminder.
If it has already been sent, please disregard this notice. If not, please proceed with payment within 5 days.
If it has already been sent, please disregard this notice. If not, please proceed with payment within 5 days.

Thank you in advance for your anticipated cooperation in this matter.
Thank you in advance for your anticipated cooperation in this matter.

Best regards
Best regards
</field>
<field name="mail_show_invoice_detail" eval="True" />
<field
name="custom_mail_text"
><![CDATA[
Our records indicate that we have not yet received the payment of the invoices mentioned in the attached document despite our first reminder.<br/>
If it has already been sent, please disregard this notice. If not, please proceed with payment within 5 days.<br/>
<br/>
Thank you in advance for your anticipated cooperation in this matter.<br/>
<br/>
Best regards
]]></field>
<field name="custom_mail_text" type="html">
<p
>Our records indicate that we have not yet received the payment of the invoices mentioned in the attached document despite our first reminder.<br
/>
If it has already been sent, please disregard this notice. If not, please proceed with payment within 5 days.</p>
<br />
<p>Thank you in advance for your anticipated cooperation in this matter.</p><br />
<br />
<p>Best regards</p>
</field>
</record>
<record model="credit.control.policy.level" id="3_time_3">
<field name="name">10 days last reminder</field>
Expand All @@ -110,32 +107,33 @@
<field name="policy_id" ref="credit_control_3_time" />
<field name="channel">letter</field>
<field name="custom_text">
Our records indicate that we still have not received the payment of the invoice mentioned below despite our two reminders.
If payment have already been sent, please disregard this notice. If not, please proceed with payment.
If your payment has not been received in the next 5 days, your file will be transfered to our debt collection agency.
Our records indicate that we still have not received the payment of the invoice mentioned below despite our two reminders.
If payment have already been sent, please disregard this notice. If not, please proceed with payment.
If your payment has not been received in the next 5 days, your file will be transferred to our debt collection agency.

Should you need us to arrange a payment plan for you, please advise.
A customer account statement is enclosed for you convenience.
Should you need us to arrange a payment plan for you, please advise.
A customer account statement is enclosed for you convenience.

Thank you in advance for your anticipated cooperation in this matter.
Thank you in advance for your anticipated cooperation in this matter.

Best regards
Best regards
</field>
<field name="mail_show_invoice_detail" eval="True" />
<field
name="custom_mail_text"
><![CDATA[
Our records indicate that we still have not received the payment of the invoices mentioned in the attached document despite our two reminders.<br/>
If payment have already been sent, please disregard this notice. If not, please proceed with payment.<br/>
If your payment has not been received in the next 5 days, your file will be transfered to our debt collection agency.<br/>
<br/>
Should you need us to arrange a payment plan for you, please advise.<br/>
A customer account statement is enclosed for you convenience.<br/>
<br/>
Thank you in advance for your anticipated cooperation in this matter.<br/>
<br/>
Best regards
]]></field>
<field name="custom_mail_text" type="html">
<p
>Our records indicate that we still have not received the payment of the invoices mentioned in the attached document despite our two reminders.<br
/>
If payment have already been sent, please disregard this notice. If not, please proceed with payment.<br
/>
If your payment has not been received in the next 5 days, your file will be transferred to our debt collection agency.</p>
<br />
<p>Should you need us to arrange a payment plan for you, please advise.<br />
A customer account statement is enclosed for you convenience.</p>
<br />
<p>Thank you in advance for your anticipated cooperation in this matter.</p>
<br />
<p>Best regards</p>
</field>
</record>
<!-- policy 2 -->
<record model="credit.control.policy" id="credit_control_2_time">
Expand All @@ -152,23 +150,23 @@
<field
name="custom_text"
>Our records indicate that we have not received the payment of the invoice mentioned below.
If it has already been sent, please disregard this notice. If not, please proceed with payment within 10 days.
If it has already been sent, please disregard this notice. If not, please proceed with payment within 10 days.

Thank you in advance for your anticipated cooperation in this matter.
Thank you in advance for your anticipated cooperation in this matter.

Best regards
Best regards
</field>
<field name="mail_show_invoice_detail" eval="True" />
<field
name="custom_mail_text"
><![CDATA[
Our records indicate that we have not received the payment of the invoices mentioned in the attached document.<br/>
If it has already been sent, please disregard this notice. If not, please proceed with payment within 10 days.<br/>
<br/>
Thank you in advance for your anticipated cooperation in this matter.<br/>
<br/>
Best regards
]]></field>
<field name="custom_mail_text" type="html">
<p
>Our records indicate that we have not received the payment of the invoices mentioned in the attached document.<br
/>
If it has already been sent, please disregard this notice. If not, please proceed with payment within 10 days.</p>
<br />
<p>Thank you in advance for your anticipated cooperation in this matter.</p>
<br />
<p>Best regards</p>
</field>
</record>
<record model="credit.control.policy.level" id="2_time_2">
<field name="name">60 days last reminder</field>
Expand All @@ -182,34 +180,33 @@
name="custom_text"
>Our records indicate that we still have not received the payment of the mentioned below invoice despite our reminder.

If payment have already been sent, please disregard this notice. If not, please proceed with payment.
If your payment has not been received in the next 5 days, your file will be transfered to our debt collection agency.
If payment have already been sent, please disregard this notice. If not, please proceed with payment.
If your payment has not been received in the next 5 days, your file will be transferred to our debt collection agency.

Should you need us to arrange a payment plan for you, please advise.
A customer account statement is enclosed for you convenience.
Should you need us to arrange a payment plan for you, please advise.
A customer account statement is enclosed for you convenience.

Thank you in advance for your anticipated cooperation in this matter.
Thank you in advance for your anticipated cooperation in this matter.

Best regards
Best regards
</field>
<field name="mail_show_invoice_detail" eval="True" />
<field
name="custom_mail_text"
><![CDATA[
Our records indicate that we still have not received the payment of the invoices mentioned in the attached document despite our reminder.
<br/>
<br/>
If payment have already been sent, please disregard this notice. If not, please proceed with payment.<br/>
If your payment has not been received in the next 5 days, your file will be transfered to our debt<br/>
collection agency.<br/>
<br/>
Should you need us to arrange a payment plan for you, please advise.<br/>
A customer account statement is enclosed for you convenience.<br/>
<br/>
Thank you in advance for your anticipated cooperation in this matter.<br/>
<br/>
Best regards
]]></field>
<field name="custom_mail_text" type="html">
<p
>Our records indicate that we still have not received the payment of the invoices mentioned in the attached document despite our reminder.</p>
<br />
<p
>If payment have already been sent, please disregard this notice. If not, please proceed with payment.<br
/>
If your payment has not been received in the next 5 days, your file will be transferred to our debt
collection agency.</p>
<br />
<p>Should you need us to arrange a payment plan for you, please advise.<br />
A customer account statement is enclosed for you convenience.</p>
<br />
<p>Thank you in advance for your anticipated cooperation in this matter.</p>
<br />
<p>Best regards</p>
</field>
</record>
<record id="base.main_company" model="res.company">
<field name="credit_policy_id" ref="credit_control_3_time" />
Expand Down
25 changes: 24 additions & 1 deletion account_credit_control/models/credit_control_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CreditControlPolicy(models.Model):
comodel_name="account.account",
string="Accounts",
required=True,
domain="[('internal_type', '=', 'receivable')]",
domain="[('account_type', '=', 'asset_receivable')]",
help="This policy will be active only for the selected accounts",
)
active = fields.Boolean(default=True)
Expand Down Expand Up @@ -223,6 +223,29 @@ def _generate_credit_lines(self, credit_control_run, default_lines_vals=None):
)
return (manual_lines, policy_lines_generated, report)

@api.model
def _name_search(
self, name="", args=None, operator="ilike", limit=100, name_get_uid=None
):
"""Alternative implementation for domain on account, equivalent to
domain="[('account_ids', 'in', property_account_receivable_id)]"
"""
account_receivable = self.env["account.account"].browse()
if self.env.context.get("account_receivable_partner_id"):
partner = self.env["res.partner"].browse(
self.env.context["account_receivable_partner_id"]
)
account_receivable = partner.property_account_receivable_id

ids = super()._name_search(name, args, operator, limit, name_get_uid)
policies = self.browse(ids)
policy_ids = []
if account_receivable:
for policy in policies:
if account_receivable.id in policy.account_ids.ids:
policy_ids.append(policy.id)
return policy_ids if account_receivable else ids


class CreditControlPolicyLevel(models.Model):
"""Define a policy level. A level allows to determine if
Expand Down
1 change: 0 additions & 1 deletion account_credit_control/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class ResPartner(models.Model):
credit_policy_id = fields.Many2one(
comodel_name="credit.control.policy",
string="Credit Control Policy",
domain="[('account_ids', 'in', property_account_receivable_id)]",
help="The Credit Control Policy used for this "
"partner. This setting can be forced on the "
"invoice. If nothing is defined, it will use "
Expand Down
1 change: 1 addition & 0 deletions account_credit_control/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@

* Enric Tobella <etobella@creublanca.es>
* Naglis Jonaitis (Versada UAB) <naglis@versada.eu>
* Andrea Stirpe <a.stirpe@onestein.nl>
18 changes: 6 additions & 12 deletions account_credit_control/tests/test_account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,21 @@ def test_action_cancel(self):
"""
journal = self.company_data["default_journal_sale"]

account_type_rec = self.env.ref("account.data_account_type_receivable")
account = self.env["account.account"].create(
{
"code": "TEST430",
"name": "Clients (test)",
"user_type_id": account_type_rec.id,
"account_type": "asset_receivable",
"reconcile": True,
}
)

tag_operation = self.env.ref("account.account_tag_operating")
account_type_inc = self.env.ref("account.data_account_type_revenue")
analytic_account = self.env["account.account"].create(
{
"code": "TEST700",
"name": "Ventes en Belgique (test)",
"user_type_id": account_type_inc.id,
"account_type": "income",
"reconcile": True,
"tag_ids": [(6, 0, [tag_operation.id])],
}
Expand Down Expand Up @@ -124,23 +122,21 @@ def test_action_cancel_draft_credit_lines(self):
"""
journal = self.company_data["default_journal_sale"]

account_type_rec = self.env.ref("account.data_account_type_receivable")
account = self.env["account.account"].create(
{
"code": "TEST430",
"name": "Clients (test)",
"user_type_id": account_type_rec.id,
"account_type": "asset_receivable",
"reconcile": True,
}
)

tag_operation = self.env.ref("account.account_tag_operating")
account_type_inc = self.env.ref("account.data_account_type_revenue")
analytic_account = self.env["account.account"].create(
{
"code": "TEST700",
"name": "Ventes en Belgique (test)",
"user_type_id": account_type_inc.id,
"account_type": "income",
"reconcile": True,
"tag_ids": [(6, 0, [tag_operation.id])],
}
Expand Down Expand Up @@ -205,23 +201,21 @@ def test_invoice_policy_wiz(self):
"""
journal = self.company_data["default_journal_sale"]

account_type_rec = self.env.ref("account.data_account_type_receivable")
account = self.env["account.account"].create(
{
"code": "TEST430",
"name": "Clients (test)",
"user_type_id": account_type_rec.id,
"account_type": "asset_receivable",
"reconcile": True,
}
)

tag_operation = self.env.ref("account.account_tag_operating")
account_type_inc = self.env.ref("account.data_account_type_revenue")
analytic_account = self.env["account.account"].create(
{
"code": "TEST700",
"name": "Ventes en Belgique (test)",
"user_type_id": account_type_inc.id,
"account_type": "income",
"reconcile": True,
"tag_ids": [(6, 0, [tag_operation.id])],
}
Expand Down
Loading

0 comments on commit 4032416

Please sign in to comment.