mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[16.0][MIG] account_spread_cost_revenue
This commit is contained in:
@@ -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",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user