Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
from . import transmit_method_substitution_rule
|
||||
from . import account_invoice
|
||||
@@ -0,0 +1,47 @@
|
||||
# Copyright 2020 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, models
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
invoices = super().create(vals_list)
|
||||
invoices.apply_transmit_method_substitutions()
|
||||
return invoices
|
||||
|
||||
def get_substitution_transmit_method(self, substitution_rules):
|
||||
transmit_method_id = False
|
||||
for substitution_rule in substitution_rules:
|
||||
domain = safe_eval(substitution_rule.domain) + [("id", "in", self.ids)]
|
||||
if self.search(domain):
|
||||
if (
|
||||
transmit_method_id
|
||||
and transmit_method_id != substitution_rule.transmit_method_id
|
||||
):
|
||||
# conflict between rules, we set the transmit
|
||||
return False
|
||||
transmit_method_id = substitution_rule.transmit_method_id
|
||||
return transmit_method_id
|
||||
|
||||
def apply_transmit_method_substitutions(self):
|
||||
substitution_rule_model = self.env["transmit.method.substitution.rule"]
|
||||
substitution_rules_by_company = (
|
||||
substitution_rule_model.get_substitution_rules_by_company()
|
||||
)
|
||||
for group in self.read_group(
|
||||
[("id", "in", self.ids), ("transmit_method_id", "!=", False)],
|
||||
["id:sum"],
|
||||
["company_id"],
|
||||
):
|
||||
invoices = self.search(group["__domain"])
|
||||
company_id = group["company_id"][0] if group["company_id"] else False
|
||||
transmit_method_id = invoices.get_substitution_transmit_method(
|
||||
substitution_rules_by_company.get(company_id, [])
|
||||
)
|
||||
if transmit_method_id:
|
||||
invoices.write({"transmit_method_id": transmit_method_id.id})
|
||||
@@ -0,0 +1,35 @@
|
||||
# Copyright 2020 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class TransmitMethodSubstitutionRule(models.Model):
|
||||
_name = "transmit.method.substitution.rule"
|
||||
_description = "Transmit Method Substitution Rule"
|
||||
|
||||
name = fields.Char(required=True)
|
||||
domain = fields.Char(required=True, default="[]")
|
||||
transmit_method_id = fields.Many2one(
|
||||
comodel_name="transmit.method", string="Transmit Method", required=True
|
||||
)
|
||||
active = fields.Boolean(default=True)
|
||||
company_id = fields.Many2one(
|
||||
comodel_name="res.company",
|
||||
string="Company",
|
||||
default=lambda self: self.env.user.company_id,
|
||||
)
|
||||
|
||||
@api.model
|
||||
def get_substitution_rules_by_company(self):
|
||||
substitution_rules_by_company = {}
|
||||
for group in self.read_group([], ["id:sum"], ["company_id"]):
|
||||
if group["company_id"]:
|
||||
company_id = group["company_id"][0]
|
||||
domain = [
|
||||
"|",
|
||||
("company_id", "=", company_id),
|
||||
("company_id", "=", False),
|
||||
]
|
||||
substitution_rules_by_company[company_id] = self.search(domain)
|
||||
return substitution_rules_by_company
|
||||
Reference in New Issue
Block a user