Initial commit: OCA Technical packages (595 packages)

This commit is contained in:
Ernad Husremovic 2025-08-29 15:43:03 +02:00
commit 2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions

View file

@ -0,0 +1,5 @@
# Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import account_move
from . import res_partner_account_brand

View file

@ -0,0 +1,58 @@
# Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class AccountMove(models.Model):
_name = "account.move"
_inherit = ["account.move", "res.brand.mixin"]
brand_id = fields.Many2one()
def _is_brand_required(self):
self.ensure_one()
if self.move_type in ("in_invoice", "in_refund"):
return False
return super()._is_brand_required()
@api.onchange("partner_id")
def _onchange_partner_id(self):
res = super()._onchange_partner_id()
if self.brand_id:
pab_model = self.env["res.partner.account.brand"]
company_id = self.company_id.id
partner = (
self.partner_id
if not company_id
else self.partner_id.with_company(company_id)
)
invoice_type = self.move_type or self.env.context.get(
"move_type", "out_invoice"
)
if partner:
rec_account = pab_model._get_partner_account_by_brand(
"asset_receivable", self.brand_id, partner
)
rec_account = (
rec_account
if rec_account
else partner.property_account_receivable_id
)
pay_account = pab_model._get_partner_account_by_brand(
"liability_payable", self.brand_id, partner
)
pay_account = (
pay_account if pay_account else partner.property_account_payable_id
)
if invoice_type in ("in_invoice", "in_refund"):
account_id = pay_account
else:
account_id = rec_account
if account_id:
self.line_ids.filtered(
lambda line, a=account_id: line.account_id.account_type
== a.account_type
).update({"account_id": account_id.id})
return res

View file

@ -0,0 +1,81 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class ResPartnerAccountBrand(models.Model):
"""This model is meant to be used in case we need to define different
receivable/payable accounts for partners"""
_name = "res.partner.account.brand"
_description = "Receivable/Payable Partner Account By Brand"
partner_id = fields.Many2one(
comodel_name="res.partner", string="Partner", required=False
)
account_id = fields.Many2one(
comodel_name="account.account",
string="Account",
required=True,
domain="[('account_type', 'in', ('liability_payable', 'asset_receivable'))]",
)
brand_id = fields.Many2one(comodel_name="res.brand", string="Brand", required=True)
account_type = fields.Selection(
string="Type",
selection=[
("liability_payable", "Payable"),
("asset_receivable", "Receivable"),
],
required=True,
)
_sql_constraints = [
(
"unique_account_by_partner",
"unique(partner_id, account_id, brand_id, account_type)",
"Partner has already an account set for this brand!",
)
]
@api.constrains("account_id", "account_type")
def _check_account_type(self):
for rec in self:
if (
rec.account_id
and rec.account_type
and rec.account_id.account_type != rec.account_type
):
raise ValidationError(
_("Please select an account of type %s") % rec.account_type
)
@api.onchange("account_type")
def _onchange_account_type(self):
self.ensure_one()
self.update({"account_id": False})
domain = [("id", "=", False)]
if self.account_type == "payable":
domain = [
("internal_type", "=", "payable"),
("deprecated", "=", False),
]
elif self.account_type == "receivable":
domain = [
("internal_type", "=", "receivable"),
("deprecated", "=", False),
]
return {"domain": {"account_id": domain}}
@api.model
def _get_partner_account_by_brand(self, account_type, brand, partner):
domain = [
("brand_id", "=", brand.id),
("account_type", "=", account_type),
]
default_rule = self.search(domain + [("partner_id", "=", False)], limit=1)
partner_rule = False
if partner:
partner_rule = self.search(domain + [("partner_id", "=", partner.id)])
return partner_rule.account_id if partner_rule else default_rule.account_id