Files

83 lines
2.7 KiB
Python
Raw Permalink Normal View History

2017-02-25 19:01:35 +01:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import ModelView, fields
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval
from trytond.transaction import Transaction
2021-12-11 17:58:41 +01:00
from trytond.wizard import Button, StateAction, StateView, Wizard
2017-02-25 19:01:35 +01:00
2018-06-26 19:11:42 +02:00
class Invoice(metaclass=PoolMeta):
2017-02-25 19:01:35 +01:00
__name__ = 'account.invoice'
@classmethod
def __setup__(cls):
2025-04-04 00:45:18 +02:00
super().__setup__()
2017-02-25 19:01:35 +01:00
cls._buttons.update({
'correct': {
'invisible': Eval('state') != 'posted',
2018-02-19 11:37:20 +01:00
'depends': ['state', 'type'],
2017-02-25 19:01:35 +01:00
},
})
@classmethod
@ModelView.button_action(
'account_invoice_correction.wizard_invoice_correct')
def correct(cls, invoices):
pass
class InvoiceCorrectStart(ModelView):
__name__ = 'account.invoice.correct.start'
invoice = fields.Many2One('account.invoice', 'Invoice', readonly=True)
lines = fields.Many2Many('account.invoice.line', None, None,
'Invoice Lines',
domain=[
('invoice', '=', Eval('invoice', -1)),
2017-02-25 19:01:35 +01:00
('type', '=', 'line'),
])
2017-02-25 19:01:35 +01:00
class InvoiceCorrect(Wizard):
__name__ = 'account.invoice.correct'
start = StateView('account.invoice.correct.start',
'account_invoice_correction.correct_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Correct', 'correct', 'tryton-ok', default=True),
])
correct = StateAction('account_invoice.act_invoice_form')
def default_start(self, fields):
context = Transaction().context
return {
'invoice': context['active_id'],
'lines': [],
}
def do_correct(self, action):
pool = Pool()
Invoice = self.model
2017-02-25 19:01:35 +01:00
Line = pool.get('account.invoice.line')
invoice = self.record
with Transaction().set_context(_account_invoice_correction=True):
correction, = Invoice.copy([invoice], default={
'lines': [],
2017-02-25 19:01:35 +01:00
})
# Copy each line one by one to get negative and positive lines
# following each other
for line in self.start.lines:
Line.copy([line], default={
'invoice': correction.id,
'quantity': -line.quantity,
})
Line.copy([line], default={
'invoice': correction.id,
})
correction.update_taxes()
2017-02-25 19:01:35 +01:00
data = {'res_id': [correction.id]}
return action, data