mirror of
https://github.com/bringout/oca-ocb-accounting.git
synced 2026-04-23 02:01:59 +02:00
19.0 vanilla
This commit is contained in:
parent
ba20ce7443
commit
768b70e05e
2357 changed files with 1057103 additions and 712486 deletions
|
|
@ -3,6 +3,7 @@
|
|||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class AccountAnalyticLine(models.Model):
|
||||
_inherit = 'account.analytic.line'
|
||||
_description = 'Analytic Line'
|
||||
|
|
@ -16,7 +17,7 @@ class AccountAnalyticLine(models.Model):
|
|||
'account.account',
|
||||
string='Financial Account',
|
||||
ondelete='restrict',
|
||||
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
|
||||
check_company=True,
|
||||
compute='_compute_general_account_id', store=True, readonly=False
|
||||
)
|
||||
journal_id = fields.Many2one(
|
||||
|
|
@ -54,7 +55,7 @@ class AccountAnalyticLine(models.Model):
|
|||
if line.move_line_id and line.general_account_id != line.move_line_id.account_id:
|
||||
raise ValidationError(_('The journal item is not linked to the correct financial account'))
|
||||
|
||||
@api.depends('move_line_id')
|
||||
@api.depends('move_line_id.partner_id')
|
||||
def _compute_partner_id(self):
|
||||
for line in self:
|
||||
line.partner_id = line.move_line_id.partner_id or line.partner_id
|
||||
|
|
@ -67,11 +68,11 @@ class AccountAnalyticLine(models.Model):
|
|||
prod_accounts = self.product_id.product_tmpl_id.with_company(self.company_id)._get_product_accounts()
|
||||
unit = self.product_uom_id
|
||||
account = prod_accounts['expense']
|
||||
if not unit or self.product_id.uom_po_id.category_id.id != unit.category_id.id:
|
||||
unit = self.product_id.uom_po_id
|
||||
if not unit:
|
||||
unit = self.product_id.uom_id
|
||||
|
||||
# Compute based on pricetype
|
||||
amount_unit = self.product_id.price_compute('standard_price', uom=unit)[self.product_id.id]
|
||||
amount_unit = self.product_id._price_compute('standard_price', uom=unit)[self.product_id.id]
|
||||
amount = amount_unit * self.unit_amount or 0.0
|
||||
result = (self.currency_id.round(amount) if self.currency_id else round(amount, 2)) * -1
|
||||
self.amount = result
|
||||
|
|
@ -86,3 +87,24 @@ class AccountAnalyticLine(models.Model):
|
|||
account=self.env['account.analytic.account'].browse(self.env.context['account_id']).name
|
||||
)
|
||||
return super().view_header_get(view_id, view_type)
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
analytic_lines = super().create(vals_list)
|
||||
analytic_lines.move_line_id._update_analytic_distribution()
|
||||
return analytic_lines
|
||||
|
||||
def write(self, vals):
|
||||
affected_move_lines = self.move_line_id
|
||||
res = super().write(vals)
|
||||
if any(field in vals for field in ['amount', 'move_line_id'] + self._get_plan_fnames()):
|
||||
if 'move_line_id' in vals:
|
||||
affected_move_lines |= self.move_line_id
|
||||
affected_move_lines._update_analytic_distribution()
|
||||
return res
|
||||
|
||||
def unlink(self):
|
||||
affected_move_lines = self.move_line_id
|
||||
res = super().unlink()
|
||||
affected_move_lines._update_analytic_distribution()
|
||||
return res
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue