[16.0][MIG] account_spread_cost_revenue

This commit is contained in:
Andrea Stirpe
2023-10-10 11:12:05 +02:00
parent e2ab9e5fdb
commit 0698663e48
22 changed files with 371 additions and 340 deletions

View File

@@ -7,6 +7,7 @@ from odoo.exceptions import UserError
class AccountSpreadTemplate(models.Model):
_name = "account.spread.template"
_inherit = "analytic.mixin"
_description = "Account Spread Template"
name = fields.Char(required=True)
@@ -147,34 +148,10 @@ class AccountSpreadTemplate(models.Model):
spread_vals["invoice_type"] = invoice_type
return spread_vals
@api.constrains("auto_spread_ids", "auto_spread")
def _check_auto_spread_ids_unique(self):
query = """
select product_id, account_id, analytic_account_id
from (
select product_id, account_id, analytic_account_id, count(*)
from account_spread_template_auto a
join account_spread_template b on a.template_id = b.id
where b.auto_spread = true and b.id in %s
group by product_id, account_id, analytic_account_id
) x where x.count > 1 """
self._cr.execute(query, [self._ids])
results = []
for res in self._cr.fetchall():
product = self.env["product.product"].browse(res[0])
account = self.env["account.account"].browse(res[1])
analytic = self.env["account.analytic.account"].browse(res[2])
results.append(
"{} / {} / {}".format(product.name, account.name, analytic.name)
)
if results:
raise UserError(
_("Followings are duplicated combinations,\n\n%s") % "\n".join(results)
)
class AccountSpreadTemplateAuto(models.Model):
_name = "account.spread.template.auto"
_inherit = "analytic.mixin"
_description = "Auto create spread, based on product/account/analytic"
template_id = fields.Many2one(
@@ -200,7 +177,3 @@ class AccountSpreadTemplateAuto(models.Model):
comodel_name="account.account",
string="Account",
)
analytic_account_id = fields.Many2one(
comodel_name="account.analytic.account",
string="Analytic",
)