def check_tax_lines(self, compute_taxes): """ Check if no tax lines are created. If existing tax lines, there are checks on the invoice and match the tax base. """ assert len(self) == 1, "Can only check one invoice at a time." account_invoice_tax = self.env['account.invoice.tax'] company_currency = self.company_id.currency_id if not self.tax_line: for tax in compute_taxes.values(): account_invoice_tax.create(tax) else: tax_key = [] precision = self.env['decimal.precision'].precision_get('Account') for tax in self.tax_line: if tax.manual: continue # Comment the following line from original method # key = (tax.tax_code_id.id, tax.base_code_id.id, # tax.account_id.id) # Group by tax id (now use this key) key = (tax.tax_id.id) tax_key.append(key) if key not in compute_taxes: raise osv.except_osv( _('Warning!'), _('Global taxes defined, but they are not in invoice' ' lines !')) base = compute_taxes[key]['base'] if float_compare(abs(base - tax.base), company_currency.rounding, precision_digits=precision) == 1: raise osv.except_osv( _('Warning!'), _('Tax base different!\nClick on compute to update' ' the tax base.')) # for key in compute_taxes: if key not in tax_key: raise osv.except_osv( _('Warning!'), _('Taxes are missing!\nClick on compute button.'))
def check_tax_lines(self, compute_taxes): """ Check if no tax lines are created. If existing tax lines, there are checks on the invoice and match the tax base. """ assert len(self) == 1, "Solo puede verificar una factura a la vez." account_invoice_tax = self.env['account.tax'] company_currency = self.company_id.currency_id if not self.tax_line: for tax in compute_taxes.values(): account_invoice_tax.create(tax) else: tax_key = [] precision = self.env['decimal.precision'].precision_get('Account') for tax in self.tax_line: if tax.manual: continue key = (tax.tax_id.id) tax_key.append(key) if key not in compute_taxes: raise exceptions.except_orm( _('Advertencia!'), _('Impuestos globales definidos, pero no están en la factura.' ' lines !')) base = compute_taxes[key]['base'] if float_compare(abs(base - tax.base), company_currency.rounding, precision_digits=precision) == 1: raise exceptions.except_orm( _('Warning!'), _('Tax base different!\nClick on compute to update' ' the tax base.')) # for key in compute_taxes: if key not in tax_key: raise exceptions.except_orm( _('Warning!'), _('Taxes are missing!\nClick on compute button.'))
def ret_and_reconcile(self, pay_amount, pay_account_id, pay_journal_id, writeoff_acc_id, writeoff_journal_id, date, name, to_wh,type_retencion): """ Make the payment of the invoice """ rp_obj = self.env['res.partner'] hola = self.ids carro = hola if self.ids : assert len(self.ids) == 1, "Solo puede pagar una factura a la vez" else: assert len(to_wh) == 1, "Solo puede pagar una factura a la vez" invoice = self.browse(self.ids) src_account_id = pay_account_id.id # Take the seq as name for move types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1} direction = types[invoice.type] l1 = { 'debit': direction * pay_amount > 0 and direction * pay_amount, 'credit': direction * pay_amount < 0 and - direction * pay_amount, 'account_id': src_account_id, 'partner_id': rp_obj._find_accounting_partner( invoice.partner_id).id, 'ref': invoice.name, 'date': date, 'currency_id': False, 'name': name } lines = [(0, 0, l1)] if type_retencion == 'wh_iva': l2 = self._get_move_lines1(to_wh, pay_journal_id, writeoff_acc_id, writeoff_journal_id, date, name) if type_retencion == 'wh_islr': l2 = self._get_move_lines2(to_wh, pay_journal_id, writeoff_acc_id, writeoff_journal_id, date, name) if type_retencion == 'wh_muni': l2 = self._get_move_lines3(to_wh, pay_journal_id, writeoff_acc_id, writeoff_journal_id, date, name) if not l2: raise exceptions.except_orm( _('Advertencia!'), _('No se crearon movimientos contables.\n Por favor, verifique si hay ' ' impuestos / conceptos para retener en las facturas!')) deb = l2[0][2]['debit'] cred = l2[0][2]['credit'] if deb < 0: l2[0][2].update({'debit': deb * direction}) if cred < 0: l2[0][2].update({'credit': cred * direction}) lines += l2 move = {'ref': name + 'de '+ str(invoice.name), 'line_ids': lines, 'journal_id': pay_journal_id, 'date': date, 'state': 'draft', 'type': 'entry' } # self.env['account.move'].create(move_vals_list) move_obj = self.env['account.move'] move_id = move_obj.create(move) return move_id line_ids = [] total = 0.0 line = self.env['account.move.line'] self._cr.execute( 'select id' ' from account_move_line' ' where move_id in (' + str(move_id.id) + ',' + str(invoice.move_id.id) + ')') lines = line.browse( [item[0] for item in self._cr.fetchall()]) for aml_brw in lines: if aml_brw.account_id.id == src_account_id: line_ids.append(aml_brw.id) total += (aml_brw.debit or 0.0) - (aml_brw.credit or 0.0) for aml_brw in invoice.payment_ids: if aml_brw.account_id.id == src_account_id: line_ids.append(aml_brw.id) total += (aml_brw.debit or 0.0) - (aml_brw.credit or 0.0) if (not round(total, self.env['decimal.precision'].precision_get( 'Withhold'))) or writeoff_acc_id: self.env['account.move.line'].reconcile( line_ids, 'manual', writeoff_acc_id, writeoff_period_id, writeoff_journal_id) self.env['account.move'].write({}) self.move_id = move_id
def ret_and_reconcile(self, pay_amount, pay_account_id, pay_journal_id, writeoff_acc_id, writeoff_journal_id, date, name, to_wh, writeoff_period_id=None): """ Make the payment of the invoice """ rp_obj = self.env['res.partner'] # TODO check if we can use different period for payment and the # writeoff line assert len(self.ids) == 1, "Can only pay one invoice at a time" invoice = self.browse(self.ids) src_account_id = invoice.account_id.id # Take the seq as name for move types = { 'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1 } direction = types[invoice.type] l1 = { 'debit': direction * pay_amount > 0 and direction * pay_amount, 'credit': direction * pay_amount < 0 and -direction * pay_amount, 'account_id': src_account_id, 'partner_id': rp_obj._find_accounting_partner(invoice.partner_id).id, 'ref': invoice.number, 'date': date, 'currency_id': False, 'name': name } lines = [(0, 0, l1)] l2 = self._get_move_lines(to_wh, pay_journal_id, writeoff_acc_id, writeoff_journal_id, date, name) # TODO: check the method _get_move_lines that is forced to return [] # and that makes that aws_customer.yml test cause a error if not l2: raise osv.except_osv( _('Warning !'), _('No accounting moves were created.\n Please, Check if there' ' are Taxes/Concepts to withhold in the Invoices!')) # rsosa: ID 57 deb = l2[0][2]['debit'] cred = l2[0][2]['credit'] if deb < 0: l2[0][2].update({'debit': deb * direction}) if cred < 0: l2[0][2].update({'credit': cred * direction}) #for line in l2: # if deb < 0: line[2].update({'debit': deb * direction}) # if cred < 0: line[2].update({'credit': cred * direction}) lines += l2 move = { 'ref': invoice.number, 'line_ids': lines, 'journal_id': pay_journal_id, 'date': date, 'state': 'draft' } move_obj = self.env['account.move'] move_id = move_obj.create(move) #move_id.post() #PARA FORZAR LA CULMINACION DE UNA TRANSACCION DE BASE DE DATOS #self.env.cr.commit() return move_id #self.env['account.move'].post(move) line_ids = [] total = 0.0 line = self.env['account.move.line'] self._cr.execute('select id' ' from account_move_line' ' where move_id in (' + str(move_id.id) + ',' + str(invoice.move_id.id) + ')') lines = line.browse([item[0] for item in self._cr.fetchall()]) for aml_brw in lines: if aml_brw.account_id.id == src_account_id: line_ids.append(aml_brw.id) total += (aml_brw.debit or 0.0) - (aml_brw.credit or 0.0) for aml_brw in invoice.payment_ids: if aml_brw.account_id.id == src_account_id: line_ids.append(aml_brw.id) total += (aml_brw.debit or 0.0) - (aml_brw.credit or 0.0) if (not round(total, self.env['decimal.precision'].precision_get( 'Withhold'))) or writeoff_acc_id: self.env['account.move.line'].reconcile(line_ids, 'manual', writeoff_acc_id, writeoff_period_id, writeoff_journal_id) #TODO REVISAR METODO RECONCILE_PARTIAL EN VERSION 8. ESTE METODO NO EXISTE EN VERSION 11 #else: # self.env['account.move.line'].reconcile_partial( # line_ids, 'manual', self.context) # Update the stored value (fields.function), so we write to trigger # recompute self.env['account.invoice'].write({}) self.move_id = move_id