diff --git a/account_credit_control/data/data.xml b/account_credit_control/data/data.xml index defc88acc..a9ddf3539 100644 --- a/account_credit_control/data/data.xml +++ b/account_credit_control/data/data.xml @@ -4,7 +4,9 @@ Credit Control Email ${user.company_id.email or ''} - Credit Control: (${object.policy_level_id.name or 'n/a'}) + Credit Control: (${object.policy_level_id.name or 'n/a'}) ${object.get_emailing_contact().id or ''} @@ -222,15 +224,13 @@ - Credit control Credit control notification account.credit.control.communication - - - + + + - diff --git a/account_credit_control/demo/res_users.xml b/account_credit_control/demo/res_users.xml index 976247930..c8dc9bc74 100644 --- a/account_credit_control/demo/res_users.xml +++ b/account_credit_control/demo/res_users.xml @@ -1,11 +1,11 @@ - + - - - + - diff --git a/account_credit_control/migrations/12.0.3.0.0/post-migration.py b/account_credit_control/migrations/12.0.3.0.0/post-migration.py index 3916416d9..4136babe4 100644 --- a/account_credit_control/migrations/12.0.3.0.0/post-migration.py +++ b/account_credit_control/migrations/12.0.3.0.0/post-migration.py @@ -41,7 +41,7 @@ def migrate(env, version): # manually changed if desired althoug they'll keep working as there's # backward compatibility with the old method communication_template = env.ref( - "account_credit_control.email_template_credit_control_base") + "account_credit_control.email_template_credit_control_base" + ) communication_template.email_to = False - communication_template.partner_to = ( - "${object.get_emailing_contact().id or ''}") + communication_template.partner_to = "${object.get_emailing_contact().id or ''}" diff --git a/account_credit_control/migrations/12.0.3.0.0/pre-migration.py b/account_credit_control/migrations/12.0.3.0.0/pre-migration.py index e240a79eb..9b042cf62 100644 --- a/account_credit_control/migrations/12.0.3.0.0/pre-migration.py +++ b/account_credit_control/migrations/12.0.3.0.0/pre-migration.py @@ -11,14 +11,9 @@ def migrate(env, version): mail_message_legacy = openupgrade.get_legacy_name("mail_message_id") openupgrade.copy_columns( env.cr, - { - "credit_control_line": [ - ("mail_message_id", mail_message_legacy, None), - ] - }, + {"credit_control_line": [("mail_message_id", mail_message_legacy, None)]}, ) # Vacuum meaningless transient data from credit.control.communication openupgrade.logged_query( - env.cr, - "DELETE FROM credit_control_communication", + env.cr, "DELETE FROM credit_control_communication", ) diff --git a/account_credit_control/models/credit_control_communication.py b/account_credit_control/models/credit_control_communication.py index c68ffaea7..5d59f97b0 100644 --- a/account_credit_control/models/credit_control_communication.py +++ b/account_credit_control/models/credit_control_communication.py @@ -17,20 +17,25 @@ class CreditControlCommunication(models.Model): comodel_name="res.partner", string="Partner", required=True, index=True ) policy_id = fields.Many2one( - related='policy_level_id.policy_id', - store=True, - index=True, + related="policy_level_id.policy_id", store=True, index=True, ) policy_level_id = fields.Many2one( - comodel_name="credit.control.policy.level", string="Level", required=True, index=True + comodel_name="credit.control.policy.level", + string="Level", + required=True, + index=True, ) currency_id = fields.Many2one( comodel_name="res.currency", string="Currency", required=True, index=True ) credit_control_line_ids = fields.One2many( - comodel_name="credit.control.line", inverse_name="communication_id", string="Credit Lines" + comodel_name="credit.control.line", + inverse_name="communication_id", + string="Credit Lines", + ) + contact_address_id = fields.Many2one( + comodel_name="res.partner", readonly=True, index=True ) - contact_address_id = fields.Many2one(comodel_name="res.partner", readonly=True, index=True) report_date = fields.Date(default=lambda self: fields.Date.context_today(self)) company_id = fields.Many2one( @@ -41,15 +46,18 @@ class CreditControlCommunication(models.Model): index=True, ) user_id = fields.Many2one( - comodel_name="res.users", default=lambda self: self.env.user, string="User", index=True, + comodel_name="res.users", + default=lambda self: self.env.user, + string="User", + index=True, ) total_invoiced = fields.Float(compute="_compute_total") total_due = fields.Float(compute="_compute_total") @api.model def _default_company(self): - company_obj = self.env['res.company'] - return company_obj._company_default_get('credit.control.policy') + company_obj = self.env["res.company"] + return company_obj._company_default_get("credit.control.policy") @api.model def _get_total(self): @@ -75,13 +83,13 @@ def _compute_total(self): def _onchange_partner_id(self): """Update address when partner changes.""" for one in self: - partners = one.env["res.partner"].search([ - ("id", "child_of", one.partner_id.id), - ]) + partners = one.env["res.partner"].search( + [("id", "child_of", one.partner_id.id)] + ) if one.contact_address_id in partners: # Contact is already child of partner return - address_ids = one.partner_id.address_get(adr_pref=['invoice']) + address_ids = one.partner_id.address_get(adr_pref=["invoice"]) one.contact_address_id = address_ids["invoice"] def get_emailing_contact(self): @@ -149,8 +157,9 @@ def _aggregate_credit_lines(self, lines): group["currency_id"], group["company_id"], ) - company_currency = self.env["res.company"].browse( - group["company_id"]).currency_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"] @@ -179,12 +188,12 @@ def _generate_emails(self): notify=True, subtype_id=self.env.ref("account_credit_control.mt_request").id, ) - comm.credit_control_line_ids \ - .filtered(lambda line: line.state == 'to_be_sent') \ - .write({"state": "queued"}) + comm.credit_control_line_ids.filtered( + lambda line: line.state == "to_be_sent" + ).write({"state": "queued"}) @api.returns("credit.control.line") def _mark_credit_line_as_sent(self): - lines = self.mapped('credit_control_line_ids') + lines = self.mapped("credit_control_line_ids") lines.write({"state": "sent"}) return lines diff --git a/account_credit_control/models/credit_control_run.py b/account_credit_control/models/credit_control_run.py index 80053f36d..5433233f5 100644 --- a/account_credit_control/models/credit_control_run.py +++ b/account_credit_control/models/credit_control_run.py @@ -62,8 +62,8 @@ def _default_policies(self): compute="_compute_credit_control_count", string="# of Credit Control Lines" ) credit_control_communication_count = fields.Integer( - compute='_compute_credit_control_count', - string='# of Credit Control Communications', + compute="_compute_credit_control_count", + string="# of Credit Control Communications", ) hide_change_state_button = fields.Boolean() company_id = fields.Many2one( @@ -182,11 +182,11 @@ def open_credit_communications(self): """Open the generated communications.""" self.ensure_one() action = self.env.ref( - 'account_credit_control.credit_control_communication_action' + "account_credit_control.credit_control_communication_action" ) action = action.read()[0] - action['domain'] = [ - ('id', 'in', self.mapped("line_ids.communication_id").ids), + action["domain"] = [ + ("id", "in", self.mapped("line_ids.communication_id").ids), ] return action diff --git a/account_credit_control/models/mail_mail.py b/account_credit_control/models/mail_mail.py index f1dd6aa57..32e70de50 100644 --- a/account_credit_control/models/mail_mail.py +++ b/account_credit_control/models/mail_mail.py @@ -17,10 +17,7 @@ def _postprocess_sent_message( mt_request = self.env.ref("account_credit_control.mt_request") if self.subtype_id == mt_request: lines = self.env["credit.control.line"].search( - [ - ("communication_id", "=", msg.res_id), - ("state", "=", "queued"), - ] + [("communication_id", "=", msg.res_id), ("state", "=", "queued")] ) new_state = "sent" if self.state == "sent" else "email_error" lines.write({"state": new_state}) diff --git a/account_credit_control/models/mail_message.py b/account_credit_control/models/mail_message.py index 334410f5d..27eaa16fc 100644 --- a/account_credit_control/models/mail_message.py +++ b/account_credit_control/models/mail_message.py @@ -5,18 +5,21 @@ class MailMessage(models.Model): - _inherit = 'mail.message' + _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' + 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 - ) - }) + message.update( + { + "is_discussion": message["is_discussion"] + or ( + message["subtype_id"] + and message["subtype_id"][0] == credit_control + ) + } + ) return result diff --git a/account_credit_control/report/account_credit_control_analysis.py b/account_credit_control/report/account_credit_control_analysis.py index af9d5e218..394cbc39d 100644 --- a/account_credit_control/report/account_credit_control_analysis.py +++ b/account_credit_control/report/account_credit_control_analysis.py @@ -83,10 +83,10 @@ def _get_sql_query(self): return """ CREATE VIEW credit_control_analysis AS - (SELECT DISTINCT ON (%s) %s - %s - ORDER BY %s) - """ % ( + (SELECT DISTINCT ON ({}) {} + {} + ORDER BY {}) + """.format( self._distinct_fields(), self._fields_to_select(), self._from_tables(), diff --git a/account_credit_control/security/account_security.xml b/account_credit_control/security/account_security.xml index e986c8c62..1b0a41bf6 100644 --- a/account_credit_control/security/account_security.xml +++ b/account_credit_control/security/account_security.xml @@ -45,9 +45,11 @@ Credit Control Communication - - - ['|',('company_id','=',False),('company_id','in',company_ids)] + + + ['|',('company_id','=',False),('company_id','in',company_ids)] Credit Control Line @@ -82,7 +84,10 @@ >['|',('company_id','=',False),('company_id','in',company_ids)] - + diff --git a/account_credit_control/views/credit_control_communication.xml b/account_credit_control/views/credit_control_communication.xml index 65062f4da..52f14118d 100644 --- a/account_credit_control/views/credit_control_communication.xml +++ b/account_credit_control/views/credit_control_communication.xml @@ -1,8 +1,7 @@ - + - credit.control.communication.form credit.control.communication @@ -11,86 +10,109 @@ - - - - + + + + - - - + + + - - - + + + - +
- - - + + +
- Credit Control Communications credit.control.communication - - - - - - - + + + + + + + - - - - - - - + + + + + + - credit.control.communication.tree credit.control.communication - - - - - - + + + + + + - Credit Control Communications ir.actions.act_window @@ -99,19 +121,20 @@

- Go to Invoicing > Credit Control > Credit Control Run to create a new credit control communication process. + Go to Invoicing > Credit Control > Credit Control Run to create a new credit control communication process.

- That's the most common way of creating these records. However, you can do it from here too if you want, by pressing Create. + That's the most common way of creating these records. However, you can do it from here too if you want, by pressing Create.

- - -
diff --git a/account_credit_control/views/credit_control_run.xml b/account_credit_control/views/credit_control_run.xml index 40ad40f58..42baaff0a 100644 --- a/account_credit_control/views/credit_control_run.xml +++ b/account_credit_control/views/credit_control_run.xml @@ -59,14 +59,27 @@ widget="statinfo" /> - - + diff --git a/account_credit_control/wizard/credit_control_emailer.py b/account_credit_control/wizard/credit_control_emailer.py index 0584ae927..a76ed0548 100644 --- a/account_credit_control/wizard/credit_control_emailer.py +++ b/account_credit_control/wizard/credit_control_emailer.py @@ -60,9 +60,10 @@ def email_lines(self): communications = self._send_emails() if not communications: - return {'type': 'ir.actions.act_window_close'} + return {"type": "ir.actions.act_window_close"} action = self.sudo().env.ref( - "account_credit_control.credit_control_communication_action") - action['name'] = _('Generated communications') - action["domain"] = [('id', 'in', communications.ids)] + "account_credit_control.credit_control_communication_action" + ) + action["name"] = _("Generated communications") + action["domain"] = [("id", "in", communications.ids)] return action diff --git a/account_credit_control/wizard/credit_control_marker.py b/account_credit_control/wizard/credit_control_marker.py index 67e2dfefd..f69d8b018 100644 --- a/account_credit_control/wizard/credit_control_marker.py +++ b/account_credit_control/wizard/credit_control_marker.py @@ -25,7 +25,12 @@ def _default_lines(self): return self._filter_lines(lines) name = fields.Selection( - selection=[("draft", "Draft"), ("ignored", "Ignored"), ("to_be_sent", "To Do"), ("sent", "Done")], + selection=[ + ("draft", "Draft"), + ("ignored", "Ignored"), + ("to_be_sent", "To Do"), + ("sent", "Done"), + ], string="Mark as", default="to_be_sent", required=True,