Fix force draft invoice

This commit is contained in:
Oscar Alvarez 2020-12-01 18:26:07 -05:00
parent 3ccb754f6c
commit 26bc6b479f
3 changed files with 57 additions and 76 deletions

View File

@ -17,18 +17,18 @@ from trytond.transaction import Transaction
from trytond.pool import Pool, PoolMeta
__all__ = ['AuxiliaryBookStart', 'PrintAuxiliaryBook', 'AuxiliaryBook',
'TrialBalanceDetailed', 'OpenChartAccountStart', 'OpenChartAccount',
'PrintTrialBalanceDetailed', 'PrintTrialBalanceDetailedStart',
'BalanceSheet', 'IncomeStatement', 'CashflowStatementContext',
'CashflowTemplate', 'Account', 'Cashflow', 'AuxiliaryParty',
'PrintPartyWithholding', 'PartyWithholdingStart', 'PartyWithholding',
'AccountConfiguration', 'AuxiliaryPartyStart', 'PrintAuxiliaryParty',
'BalanceSheetCOLGAAP', 'PrintBalanceSheetCOLGAAPStart',
'PrintBalanceSheetCOLGAAP', 'PrintIncomeStatementCOLGAAPStart',
'PrintTrialBalanceStart', 'PrintTrialBalance', 'TrialBalanceClassic',
'PrintIncomeStatementCOLGAAP', 'IncomeStatementCOLGAAP',
'CashflowStatement',
__all__ = [
'AuxiliaryBookStart', 'PrintAuxiliaryBook', 'AuxiliaryBook',
'TrialBalanceDetailed', 'OpenChartAccountStart', 'OpenChartAccount',
'PrintTrialBalanceDetailed', 'PrintTrialBalanceDetailedStart',
'BalanceSheet', 'IncomeStatement', 'CashflowStatementContext',
'CashflowTemplate', 'Account', 'Cashflow', 'AuxiliaryParty',
'PrintPartyWithholding', 'PartyWithholdingStart', 'PartyWithholding',
'AccountConfiguration', 'AuxiliaryPartyStart', 'PrintAuxiliaryParty',
'BalanceSheetCOLGAAP', 'PrintBalanceSheetCOLGAAPStart', 'CashflowStatement',
'PrintBalanceSheetCOLGAAP', 'PrintIncomeStatementCOLGAAPStart',
'PrintTrialBalanceStart', 'PrintTrialBalance', 'TrialBalanceClassic',
'PrintIncomeStatementCOLGAAP', 'IncomeStatementCOLGAAP',
]
_ZERO = Decimal('0.0')
@ -71,8 +71,7 @@ def compute_report(data, domain, codes, kind='income'):
view_accounts = Account.search(domain)
reduce_ids = [a.id for a in view_accounts
if len(a.code) <= len_code]
reduce_ids = [a.id for a in view_accounts if len(a.code) <= len_code]
with Transaction().set_context(ctx):
accounts = Account.search([
@ -158,7 +157,6 @@ class Account(metaclass=PoolMeta):
@classmethod
def __setup__(cls):
super(Account, cls).__setup__()
table = cls.__table__()
cls._error_messages.update({
'bad_operation': ('Operación No permitida.'),
})
@ -173,7 +171,7 @@ class AuxiliaryBookStart(ModelView):
'Auxiliary Book Start'
__name__ = 'account_col.print_auxiliary_book.start'
fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year',
required=True)
required=True)
start_period = fields.Many2One('account.period', 'Start Period',
domain=[
('fiscalyear', '=', Eval('fiscalyear')),
@ -395,8 +393,7 @@ class AuxiliaryBook(Report):
return report_context
@classmethod
def get_lines(cls, accounts, periods, posted, party=None,
reference=None):
def get_lines(cls, accounts, periods, posted, party=None, reference=None):
MoveLine = Pool().get('account.move.line')
clause = [
('account', 'in', [a.id for a in accounts]),
@ -421,7 +418,6 @@ class AuxiliaryBook(Report):
@classmethod
def lines(cls, accounts, periods, posted, party=None, reference=None):
Move = Pool().get('account.move')
res = dict((a.id, []) for a in accounts)
account2lines = cls.get_lines(accounts, periods, posted, party, reference)
@ -459,7 +455,7 @@ class PrintTrialBalanceDetailedStart(ModelView):
'Print Trial Balance Detailed'
__name__ = 'account_col.print_trial_balance_detailed.start'
fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year',
required=True, depends=['start_period', 'end_period'])
required=True, depends=['start_period', 'end_period'])
start_period = fields.Many2One('account.period', 'Start Period',
domain=[
('fiscalyear', '=', Eval('fiscalyear')),
@ -589,7 +585,6 @@ class TrialBalanceDetailed(Report):
('end_date', '<=', fiscalyear.start_date),
])
if data['end_period']:
end_period = Period(data['end_period'])
end_periods = Period.search([
@ -694,8 +689,7 @@ class TrialBalanceDetailed(Report):
parties = {p['id'] : p for p in parties_obj}
else:
parties = {p : p for p in parties_ids}
parties = {p: p for p in parties_ids}
def _get_process_result(kind, values):
for val in values:
@ -774,7 +768,8 @@ class TrialBalanceDetailed(Report):
class BalanceSheetContextCol(BalanceSheetContext):
'Balance Sheet Context'
__name__ = 'account.balance_sheet.col.context'
utility_temp = fields.Boolean('Utility Temp', help='Permited see the utility without have any account move')
utility_temp = fields.Boolean('Utility Temp',
help='Permited see the utility without have any account move')
class BalanceSheet(Report):
@ -845,13 +840,6 @@ class IncomeStatement(Report):
])
accounts_types = []
company_id = Transaction().context.get('company')
company = Company(company_id)
print(context)
print('---------------------------------------------------')
print(context_fields)
print('---------------------------------------------------')
print(report_context['data'])
print('---------------------------------------------------')
records = Type(report_context['data']['id'])
fiscalyear_id = Transaction().context.get('fiscalyear')
fiscalyear_cmp = Transaction().context.get('fiscalyear_cmp')
@ -865,7 +853,7 @@ class IncomeStatement(Report):
if end_period:
end_period = Period(end_period)
dom_periods= [
dom_periods = [
('type', '=', 'standard'),
('fiscalyear', '=', fiscalyear_id),
]
@ -879,7 +867,7 @@ class IncomeStatement(Report):
with Transaction().set_context(periods=periods_ids):
while types:
type_ = types.pop()
if type_.income_statement == False:
if type_.income_statement is False:
accounts = Account.search([
('type', '=', type_.id),
('kind', '!=', 'view'),
@ -923,7 +911,7 @@ class CashflowTemplate(ModelSQL, ModelView):
__name__ = 'account.account.cashflow.template'
name = fields.Char('Name', required=True, translate=True)
parent = fields.Many2One('account.account.cashflow.template', 'Parent',
ondelete="RESTRICT")
ondelete="RESTRICT")
childs = fields.One2Many('account.account.cashflow.template', 'parent',
'Children')
sequence = fields.Integer('Sequence')
@ -945,7 +933,7 @@ class CashflowTemplate(ModelSQL, ModelView):
@staticmethod
def order_sequence(tables):
table, _ = tables[None]
return [table.sequence == None, table.sequence]
return [table.sequence is None, table.sequence]
@staticmethod
def default_display_balance():
@ -1050,9 +1038,7 @@ class Cashflow(ModelSQL, ModelView):
ondelete="RESTRICT")
template = fields.Many2One('account.account.cashflow.template', 'Template')
accounts = fields.One2Many('account.account', 'cashflow', 'Accounts',
add_remove=[], domain=[
('kind', '!=', 'view'),
])
add_remove=[], domain=[('kind', '!=', 'view')])
@classmethod
def __setup__(cls):
@ -1067,7 +1053,7 @@ class Cashflow(ModelSQL, ModelView):
@staticmethod
def order_sequence(tables):
table, _ = tables[None]
return [table.sequence == None, table.sequence]
return [table.sequence is None, table.sequence]
@staticmethod
def default_balance_sheet():
@ -1084,7 +1070,6 @@ class Cashflow(ModelSQL, ModelView):
def get_currency_digits(self, name):
return self.company.currency.digits
@classmethod
def get_ctx(cls, fiscalyear=False):
Period = Pool().get('account.period')
@ -1412,9 +1397,9 @@ class PartyWithholding(Report):
class AccountConfiguration(metaclass=PoolMeta):
__name__ = 'account.configuration'
equivalent_invoice_sec = fields.Many2One('ir.sequence',
'Equivalent Invoice', domain=[
'Equivalent Invoice', domain=[
('code', '=', 'account.invoice')
])
])
class AuxiliaryPartyStart(ModelView):

View File

@ -4,11 +4,10 @@ from sql import Table
from decimal import Decimal
from trytond.model import ModelView, fields
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval, Bool, PYSONEncoder
from trytond.wizard import Wizard, StateView, Button, StateAction, StateReport, StateTransition
from trytond.pyson import Eval
from trytond.wizard import Wizard, StateView, Button, StateReport, StateTransition
from trytond.transaction import Transaction
from trytond.report import Report
from datetime import timedelta
conversor = None
try:
@ -17,10 +16,12 @@ try:
except:
print("Warning: Does not possible import numword module, please install it...!")
__all__ = ['Invoice', 'InvoiceForceDraft', 'EquivalentInvoice',
'InvoiceFixNumberStart', 'InvoiceFixNumber', 'InvoiceLine',
'MovesInvoicesStart', 'MovesInvoices', 'MovesInvoicesReport',
'InvoiceFixNumberAlternateStart', 'InvoiceFixNumberAlternate']
__all__ = [
'Invoice', 'InvoiceForceDraft', 'EquivalentInvoice',
'InvoiceFixNumberStart', 'InvoiceFixNumber', 'InvoiceLine',
'MovesInvoicesStart', 'MovesInvoices', 'MovesInvoicesReport',
'InvoiceFixNumberAlternateStart', 'InvoiceFixNumberAlternate'
]
_ZERO = Decimal('0.00')
@ -178,6 +179,9 @@ class Invoice(metaclass=PoolMeta):
def post(cls, invoices):
super(Invoice, cls).post(invoices)
for inv in invoices:
inv.write([inv], {
'untaxed_amount_cache': inv.untaxed_amount
})
if inv.invoice_type == "" or inv.invoice_type is None:
inv.raise_user_error('invalid_type_invoice')
return
@ -251,14 +255,6 @@ class Invoice(metaclass=PoolMeta):
line.description = self.description
return move
@classmethod
def post(cls, invoices):
for invoice in invoices:
invoice.write([invoice], {
'untaxed_amount_cache': invoice.untaxed_amount
})
super(Invoice, cls).post(invoices)
def get_lines_to_pay_cache(self):
Line = Pool().get('account.move.line')
if self.lines_to_pay:
@ -338,8 +334,12 @@ class InvoiceForceDraft(Wizard):
cursor = Transaction().connection.cursor()
if id_:
cursor.execute(*account_invoice.update(
columns=[account_invoice.state, account_invoice.invoice_report_cache],
values=["validated", None],
columns=[
account_invoice.state,
account_invoice.invoice_report_cache,
account_invoice.accounting_date,
],
values=["validated", None, None],
where=account_invoice.id == id_)
)
if invoice.move:
@ -375,7 +375,7 @@ class InvoiceFixNumber(Wizard):
'account_col.invoice_fix_number_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Ok', 'accept', 'tryton-ok', default=True),
])
])
accept = StateTransition()
def transition_accept(self):
@ -404,7 +404,7 @@ class InvoiceFixNumberAlternate(Wizard):
'account_col.invoice_fix_number_alternate_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Ok', 'accept', 'tryton-ok', default=True),
])
])
accept = StateTransition()
def transition_accept(self):
@ -450,7 +450,7 @@ class MovesInvoices(Wizard):
'account_col.moves_invoices_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Print', 'print_', 'tryton-ok', default=True),
])
])
print_ = StateReport('account_invoice.moves_report')
def do_print_(self, action):
@ -487,7 +487,6 @@ class MovesInvoicesReport(Report):
]
return dom_invoices
@classmethod
def get_context(cls, records, data):
report_context = super(MovesInvoicesReport, cls).get_context(records, data)

View File

@ -1,13 +1,12 @@
# 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 sql import Table
from datetime import datetime, date
from datetime import date
from trytond.transaction import Transaction
from trytond.wizard import Wizard, StateTransition
from trytond.pyson import Bool, Eval, Or, Not
from trytond.pyson import Bool, Eval, Not
from trytond.pool import PoolMeta, Pool
from trytond.model import Workflow, ModelView, fields
from itertools import groupby, chain
from trytond.model import ModelView, fields
from itertools import groupby
from functools import partial
__all__ = ['PurchaseForceDraft', 'Purchase', 'PurchaseLine']
@ -20,11 +19,11 @@ class Purchase(metaclass=PoolMeta):
def __setup__(cls):
super(Purchase, cls).__setup__()
cls._buttons.update({
'wizard_generate_shipment_invoice': {
'invisible': Eval('state').in_(['done', 'processing', 'cancel']),
'readonly': Not(Bool(Eval('lines'))),
},
})
'wizard_generate_shipment_invoice': {
'invisible': Eval('state').in_(['done', 'processing', 'cancel']),
'readonly': Not(Bool(Eval('lines'))),
},
})
cls._states_cached = ['quotation', 'confirmed', 'done', 'cancel']
@classmethod
@ -83,7 +82,6 @@ class Purchase(metaclass=PoolMeta):
if purchase.is_done():
cls.do([purchase])
def create_shipment(self, shipment_type):
'''
Create and return shipments of type shipment_type
@ -143,7 +141,6 @@ class Purchase(metaclass=PoolMeta):
values.update(dict(key))
return Shipment(**values)
@classmethod
def quote(cls, purchases):
cls.store_cache(purchases)
@ -184,7 +181,7 @@ class PurchaseLine(metaclass=PoolMeta):
# # return self.purchase.warehouse.storage_location.id
# # else:
# # return self.purchase.party.supplier_location.id
#
class PurchaseForceDraft(Wizard):
'Purchase Force Draft'