Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to check and complete value of journal entry method in Odoo

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 327
    Comment on it

    If you want to check and complete value of journal entry method in Odoo follow the following code:

     

    if 'account_id' not in vals or 'journal_id' not in vals:
                raise UserError(_("It is mandatory to specify an account and a journal to create a write-off."))
            if ('debit' in vals) ^ ('credit' in vals):
                raise UserError(_("Either pass both debit and credit or none."))
            if 'date' not in vals:
                vals['date'] = self._context.get('date_p') or time.strftime('%Y-%m-%d')
            if 'name' not in vals:
                vals['name'] = self._context.get('comment') or _('Write-Off')
            #compute the writeoff amount if not given
            if 'credit' not in vals and 'debit' not in vals:
                amount = sum([r.amount_residual for r in self])
                vals['credit'] = amount > 0 and amount or 0.0
                vals['debit'] = amount < 0 and abs(amount) or 0.0
            vals['partner_id'] = self.env['res.partner']._find_accounting_partner(self[0].partner_id).id
            company_currency = self[0].account_id.company_id.currency_id
            account_currency = self[0].account_id.currency_id or company_currency
            if 'amount_currency' not in vals and account_currency != company_currency:
                vals['currency_id'] = account_currency
                vals['amount_currency'] = sum([r.amount_residual_currency for r in self])
    
            # Writeoff line in the account of self
            first_line_dict = vals.copy()
            first_line_dict['account_id'] = self[0].account_id.id
            if 'analytic_account_id' in vals:
                del vals['analytic_account_id']
    
            # Writeoff line in specified writeoff account
            second_line_dict = vals.copy()
            second_line_dict['debit'], second_line_dict['credit'] = second_line_dict['credit'], second_line_dict['debit']
            if 'amount_currency' in vals:
                second_line_dict['amount_currency'] = -second_line_dict['amount_currency']
    
            # Create the move
            writeoff_move = self.env['account.move'].create({
                'journal_id': vals['journal_id'],
                'date': vals['date'],
                'state': 'draft',
                'line_ids': [(0, 0, first_line_dict), (0, 0, second_line_dict)],
            })
            writeoff_move.post()
    
            # Return the writeoff move.line which is to be reconciled
            return writeoff_move.line_ids.filtered(lambda r: r.account_id == self[0].account_id)
    
        @api.multi
        def remove_move_reconcile(self):
            """ Undo a reconciliation """
            if not self:
                return True
            rec_move_ids = self.env['account.partial.reconcile']
            for account_move_line in self:
                rec_move_ids += account_move_line.matched_debit_ids
                rec_move_ids += account_move_line.matched_credit_ids
            return rec_move_ids.unlink()
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: