Hi i would like to generate a printout after work with the wizard “credit”, I have remarked that the date of the invoice change automatically to today date(default_date) , But what i want in my printout that i would generated is display the origin date of the invoice that I have made already when i have posted the invoice by me.
I have added 2 methods to get this previous date , Here is the code:
1/I have defined a new field named “origins_date_invoice” on the class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
origins_date_invoice = fields.Function(fields.Date('Origins Date invoice'), 'get_origins_date_invoice')
2/then the method :get_origins_date_invoice
def get_origins_date_invoice(self, name):
return ', '.join(set(filter(None,
(str(l.origin_date) for l in self.lines)))).strftime("%d/%m/%Y")
and a method origin_date
@property
def origin_date(self):
if isinstance(self.origin, self.__class__):
return self.origin.invoice.invoice_date
else:
return " "
3/I do no really may be i have did a mistake there in this code , because when i have called this field to print it in my invoice_printout by this line of code:
<text:p text:style-name="P9"><text:span text:style-name="T1">Date:</text:span><text:span text:style-name="T2"> </text:span><text:span text:style-name="T2"><text:placeholder text:placeholder-type="text"><format_date(record.origins_date_invoice, record.company.party.lang) if record.origins_date_invoice else format_date(datetime.date.today(), record.company.party.lang)></text:placeholder></text:span></text:p>
An error was displayed and this is the traceback:
File "/lib/python3.7/site-packages/trytond/modules/account_invoice/invoice.py", line 1193, in get_origins_date_invoice
(str(l.origin_date) for l in self.lines)))).strftime("%d/%m/%Y")
AttributeError: 'str' object has no attribute 'strftime'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/lib/python3.7/site-packages/genshi/template/eval.py", line 307, in lookup_attr
val = obj[key]
TypeError: 'TranslateModel' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/lib/python3.7/site-packages/genshi/template/eval.py", line 160, in evaluate
return eval(self.code, _globals, {'__data__': data})
File "<string>", line 1288, in <Expression '__relatorio_escape_invalid_chars(format_date(record.origins_date_invoice, record.company.party.lang) if record.origins_date_invoice else format_date(datetime.date.today(), record.company.party.lang))'>
File "/lib/python3.7/site-packages/genshi/template/eval.py", line 309, in lookup_attr
val = cls.undefined(key, owner=obj)
File "/lib/python3.7/site-packages/genshi/template/eval.py", line 397, in undefined
raise UndefinedError(key, owner=owner)
genshi.template.eval.UndefinedError: <trytond.report.report.Report._get_records.<locals>.TranslateModel object at 0x7f9fcf856668> has no member named "origins_date_invoice"
How i can solve that, Thanks in advance.