Skip to content

Commit

Permalink
[IMP] account_credit_control: Compute messages as discussion and impr…
Browse files Browse the repository at this point in the history
…ove multicompany support
  • Loading branch information
etobella authored and cesar-tecnativa committed Jun 13, 2022
1 parent 756ff4c commit b77b14c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions account_credit_control/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from . import credit_control_policy
from . import credit_control_run
from . import mail_mail
from . import mail_message
from . import res_company
from . import res_partner
from . import res_config_settings
13 changes: 10 additions & 3 deletions account_credit_control/models/credit_control_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ def get_email(self):

@api.model
@api.returns("credit.control.line")
def _get_credit_lines(self, line_ids, partner_id, level_id, currency_id):
def _get_credit_lines(
self, line_ids, partner_id, level_id, currency_id, company_id
):
""" Return credit lines related to a partner and a policy level """
cr_line_obj = self.env["credit.control.line"]
cr_lines = cr_line_obj.search(
Expand All @@ -110,6 +112,7 @@ def _get_credit_lines(self, line_ids, partner_id, level_id, currency_id):
("partner_id", "=", partner_id),
("policy_level_id", "=", level_id),
("currency_id", "=", currency_id),
("company_id", "=", company_id),
]
)
return cr_lines
Expand All @@ -124,7 +127,8 @@ def _aggregate_credit_lines(self, lines):
sql = (
"SELECT distinct partner_id, policy_level_id, "
" credit_control_line.currency_id, "
" credit_control_policy_level.level"
" credit_control_policy_level.level, "
" credit_control_line.company_id "
" FROM credit_control_line JOIN credit_control_policy_level "
" ON (credit_control_line.policy_level_id = "
" credit_control_policy_level.id)"
Expand All @@ -135,7 +139,6 @@ def _aggregate_credit_lines(self, lines):
cr = self.env.cr
cr.execute(sql, (tuple(lines.ids),))
res = cr.dictfetchall()
company_currency = self.env.user.company_id.currency_id
datas = []
for group in res:
data = {}
Expand All @@ -144,11 +147,15 @@ def _aggregate_credit_lines(self, lines):
group["partner_id"],
group["policy_level_id"],
group["currency_id"],
group["company_id"],
)
company_currency = self.env["res.company"].browse(
group["company_id"]).currency_id
data["credit_control_line_ids"] = [(6, 0, level_lines.ids)]
data["partner_id"] = group["partner_id"]
data["policy_level_id"] = group["policy_level_id"]
data["currency_id"] = group["currency_id"] or company_currency.id
data["company_id"] = group["company_id"]
datas.append(data)
return datas

Expand Down
2 changes: 2 additions & 0 deletions account_credit_control/models/credit_control_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def _default_policies(self):
comodel_name="res.company",
string="Company",
default=lambda self: self.env.company,
readonly=True,
states={"draft": [("readonly", False)]},
index=True,
)

Expand Down
22 changes: 22 additions & 0 deletions account_credit_control/models/mail_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2020 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class MailMessage(models.Model):
_inherit = 'mail.message'

def message_format(self):
result = super().message_format()
credit_control = self.env['ir.model.data'].xmlid_to_res_id(
'account_credit_control.mt_request'
)
for message in result:
message.update({
'is_discussion': message['is_discussion'] or (
message['subtype_id'] and
message['subtype_id'][0] == credit_control
)
})
return result
2 changes: 2 additions & 0 deletions account_credit_control/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
* Ernesto Tejeda
* Pedro M. Baeza
* Jairo Llopis

* Enric Tobella <[email protected]>
1 change: 1 addition & 0 deletions account_credit_control/views/credit_control_run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
</div>
<group>
<field name="date" />
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}" />
<field name="hide_change_state_button" invisible="1" />
</group>
<notebook>
Expand Down

0 comments on commit b77b14c

Please sign in to comment.