I've been working on a module for interests. What I have to do is to make possible to create an invoice which has interests from overdue invoices as invoice lines. To do this, I need to pass few fields to another window with new invoice creation. Here is my problem. I tried to pass field value of invoice comment as a test. But when I add comment field with additional default, I noticed, that default is not read at all. When I edit this field in different way (e.g. I add readonly=False) then changes are visible. Only default do not work. Anyone know why?
Original field:
comment = fields.Text('Additional Information', readonly=True, states={'draft': [('readonly', False)]})
Class that inherit account.invoice:
class InterestNote(models.Model):
_inherit = 'account.invoice'
_translate = True
interest_paid = fields.Boolean(string='Are interests paid?', help='Boolean to see if interests are already paid.',
default=False)
@api.multi
def interest_note(self):
_logger.info(f'ID FAKTURY: {self.id}')
_logger.info(f'NUMER FAKTURY: {self.number}')
_logger.info(f'PARTNER: {self.partner_id}')
_logger.info(f'COMMENT: {self.comment}')
_logger.info(f'COMMENT TYP: {type(self.comment)}')
com = self.comment
_logger.info(f'COM: {com}')
_logger.info(f'COM TYPE: {type(com)}')
return {
'name': 'Create new interest note',
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'account.invoice',
'context': {'t_comment': com},
'target': 'new'
}
@api.model
def get_comment_test(self):
_logger.info('FUNKCJA TEST ROZPOCZYNA SIĘ')
test_com = self.env.context.get('t_comment')
_logger.info(f'TEST COM: {test_com}')
_logger.info(f'TEST COM TYPE: {type(test_com)}')
if not test_com:
test_com = ''
return test_com
comment = fields.Text('Additional Information', default=get_comment_test,
readonly=False, states={'draft': [('readonly', False)]})
Method interest_note works fine, it is callable but button and when I clicked it, the log messages appear normally. What should happen, is after clicking the button, new windows to create an invoice pop up, with filled comment field, after the invoice from which the button was clicked. When I write default='get_comment_test' it also do not work. So the get_comment_test method, but with default. Logger message from this method never showed up on logs. Funny thing is that in Odoo 11 I've done something almost identical and it worked. Only in 12 I have this issue. Anyone have an idea what is going on?
Here is an example (odoo v12):
Call new form and set three fields by default value (order_id, partner_id, order_line)
return {
'name': _('Check'),
'view_type': 'form',
'view_mode': 'form',
'res_model': 'check.purchase.order.lines',
'views': [
(form_view.id, 'form'),
],
'type': 'ir.actions.act_window',
'target': 'current',
'context': {
'default_order_id': self.id,
'default_partner_id': self.partner_id.id,
'default_order_line': self.get_unverified_record_ids()
},
Standard construction: write 'context': {'default_field_name': value}
In your example: write 'context': {'default_t_comment': com}
@Gleb I have no idea what are you writing. It has no connection to invoices... I tried to convert it to my example and it didn't work anyway. My question is simple really. Why it do not work? Show me error in my code, and write correction. Not entire examples, which are not connected to my issue and solving nothing.