summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/account_move_line.py
blob: 7c95d4efab6f8f1ce67f72a9ffde583aa201ec2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from odoo import models, api, fields


class AccountMoveLine(models.Model):
    _inherit = "account.move.line"

    cost_centre_id = fields.Many2one('cost.centre', string='Cost Centre')
    is_required = fields.Boolean(string='Is Required', compute='_compute_is_required')
    analytic_account_ids = fields.Many2many('account.analytic.account', string='Analytic Account')
    line_no = fields.Integer('No', default=0)

    @api.onchange('account_id')
    def _onchange_account_id(self):
        for account in self:
            analytic_account = account.account_id.analytic_tag_ids
            account.analytic_tag_ids = analytic_account

    @api.onchange('account_id')
    def _compute_is_required(self):
        for account in self:
            if account.account_id.code and account.account_id.code[0] in ['6', '7']:
                account.is_required = True
            else:
                account.is_required = False
    
    @api.model_create_multi
    def create(self, vals_list):
        for vals in vals_list:
            if 'move_id' in vals:
                move = self.env['account.move'].browse(vals['move_id'])
                if move.move_type == 'entry' and move.is_hr == True:
                    vals['name'] = move.ref
        return super().create(vals_list)