account_analytic_plan.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. from odoo import fields, models
  3. class AccountAnalyticApplicability(models.Model):
  4. _inherit = 'account.analytic.applicability'
  5. _description = "Analytic Plan's Applicabilities"
  6. business_domain = fields.Selection(
  7. selection_add=[
  8. ('invoice', 'Invoice'),
  9. ('bill', 'Vendor Bill'),
  10. ],
  11. ondelete={
  12. 'invoice': 'cascade',
  13. 'bill': 'cascade',
  14. },
  15. )
  16. account_prefix = fields.Char(
  17. string='Financial Accounts Prefix',
  18. help="Prefix that defines which accounts from the financial accounting this applicability should apply on.",
  19. )
  20. product_categ_id = fields.Many2one(
  21. 'product.category',
  22. string='Product Category'
  23. )
  24. def _get_score(self, **kwargs):
  25. score = super(AccountAnalyticApplicability, self)._get_score(**kwargs)
  26. if score == -1:
  27. return -1
  28. product = self.env['product.product'].browse(kwargs.get('product', None))
  29. account = self.env['account.account'].browse(kwargs.get('account', None))
  30. if self.account_prefix:
  31. if account and account.code.startswith(self.account_prefix):
  32. score += 1
  33. else:
  34. return -1
  35. if self.product_categ_id:
  36. if product and product.categ_id == self.product_categ_id:
  37. score += 1
  38. else:
  39. return -1
  40. return score