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
    • 330
    Comment on it

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

     

    1. if 'account_id' not in vals or 'journal_id' not in vals:
    2. raise UserError(_("It is mandatory to specify an account and a journal to create a write-off."))
    3. if ('debit' in vals) ^ ('credit' in vals):
    4. raise UserError(_("Either pass both debit and credit or none."))
    5. if 'date' not in vals:
    6. vals['date'] = self._context.get('date_p') or time.strftime('%Y-%m-%d')
    7. if 'name' not in vals:
    8. vals['name'] = self._context.get('comment') or _('Write-Off')
    9. #compute the writeoff amount if not given
    10. if 'credit' not in vals and 'debit' not in vals:
    11. amount = sum([r.amount_residual for r in self])
    12. vals['credit'] = amount > 0 and amount or 0.0
    13. vals['debit'] = amount < 0 and abs(amount) or 0.0
    14. vals['partner_id'] = self.env['res.partner']._find_accounting_partner(self[0].partner_id).id
    15. company_currency = self[0].account_id.company_id.currency_id
    16. account_currency = self[0].account_id.currency_id or company_currency
    17. if 'amount_currency' not in vals and account_currency != company_currency:
    18. vals['currency_id'] = account_currency
    19. vals['amount_currency'] = sum([r.amount_residual_currency for r in self])
    20.  
    21. # Writeoff line in the account of self
    22. first_line_dict = vals.copy()
    23. first_line_dict['account_id'] = self[0].account_id.id
    24. if 'analytic_account_id' in vals:
    25. del vals['analytic_account_id']
    26.  
    27. # Writeoff line in specified writeoff account
    28. second_line_dict = vals.copy()
    29. second_line_dict['debit'], second_line_dict['credit'] = second_line_dict['credit'], second_line_dict['debit']
    30. if 'amount_currency' in vals:
    31. second_line_dict['amount_currency'] = -second_line_dict['amount_currency']
    32.  
    33. # Create the move
    34. writeoff_move = self.env['account.move'].create({
    35. 'journal_id': vals['journal_id'],
    36. 'date': vals['date'],
    37. 'state': 'draft',
    38. 'line_ids': [(0, 0, first_line_dict), (0, 0, second_line_dict)],
    39. })
    40. writeoff_move.post()
    41.  
    42. # Return the writeoff move.line which is to be reconciled
    43. return writeoff_move.line_ids.filtered(lambda r: r.account_id == self[0].account_id)
    44.  
    45. @api.multi
    46. def remove_move_reconcile(self):
    47. """ Undo a reconciliation """
    48. if not self:
    49. return True
    50. rec_move_ids = self.env['account.partial.reconcile']
    51. for account_move_line in self:
    52. rec_move_ids += account_move_line.matched_debit_ids
    53. rec_move_ids += account_move_line.matched_credit_ids
    54. return rec_move_ids.unlink()
    55.  

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: