Odoo Hilfe

0

0
4 Answers
0
Maks
07.06.19, 05:22

@Zbik

Hello. I tried adding view_id, because everything else I have the same (without target) and still it doesn't work. What I found interesting, is that on one field, my default works just fine. In comment it doesn't.


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)
# tester = fields.Text(string='TEST', default=get_comment_test)

@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
# ctx = dict(
# type='out_invoice',
# comment=com
# )
_logger.info(f'COM: {com}')
_logger.info(f'COM TYPE: {type(com)}')

# inv_obj = self.env['account.invoice']
# inv = inv_obj.create(ctx)
# _logger.info(f'ID FAKTURY INV: {inv.id}')
# return {'type': 'ir.actions.act_window_close'}

return {
'name': 'Create new interest note',
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'view_id': self.env.ref('account.invoice_form').id,
'res_model': 'account.invoice',
'context': {
'type': 'out_invoice',
'default_type': 'out_invoice',
'comment': com,
'default_comment': com
},
'target': 'current'
}

@api.model
def get_comment_test(self):
_logger.info('FUNKCJA TEST ROZPOCZYNA SIĘ')
test_com = self.env.context.get('comment')
_logger.info(f'TEST COM: {test_com}')
_logger.info(f'TEST COM TYPE: {type(test_com)}')

if not test_com:
test_com = '456'

return test_com

comment = fields.Text('Additional Information', default=get_comment_test,
readonly=True, states={'draft': [('readonly', False)]})
tester = fields.Text(string='TEST', default=get_comment_test)

Field comment is still without any values when new invoice, but field tester works. Why is that? It's so confusing right now, I really do not understand why in one field something works, but in another it doesn't.

3 Comments
Zbik
07.06.19, 05:39

Steps:

1. Your module set comment - for example: comment = "XYZ"

2. Now is started method in module sale

3. Field invoice comment is set in module sale - in this case comment = self.env.user.company_id.sale_note

4. sale_note is porobably False => in effect comment = False

Maks
07.06.19, 07:46

What? My module is inheriting an "account.invoice", and field comment is also in this module. What I'm trying to do is to create an invoice from within another invoice, and pass a field to newly created one. It has nothing to do with sale. And I already told my issue few times, I really don't know why people on this forum so often act like they don't know the question, but they give an answer anyway. My methods works. Method get_comment_test works. In field tester everything seems fine, default method get_comment_test work. This do not work only in comment. default for comment do not work, where change in readonly is working, so only this default on this particular field cause problems. Does anyone know why, and how to solve it?

Zbik
11.06.19, 12:44

If you have the module sale installed and field "Default Terms & Conditions" in sale config is checked, value in field comment depends on it. Too bad you do not understand. Insert "LOREM IPSUM" in Default Terms & Conditions and see on effect.

0
Avatar

Zbik

--Zbik--
12143
| 7 6 9
Łódź, Polen
--Zbik--


Zbik
06.06.19, 15:26

Your problem is probably related to something else.
In module sele field comment is redefined too.
See:
def _default_comment(self):
invoice_type = self.env.context.get('type', 'out_invoice')
if invoice_type == 'out_invoice' and self.env['ir.config_parameter'].sudo().get_param('sale.use_sale_note'):
return self.env.user.company_id.sale_note

comment = fields.Text(default=_default_comment)

If your module not depends on sale then result in this field may be different than you expect .

PS. It is easier to use (if sale not inherit, without redefinition the commment field):  

return {
  'name': 'Create new interest note',
  'type': 'ir.actions.act_window',
  'view_type': 'form',
  'view_mode': 'form',
  'view_id': self.env.ref('account.invoice_form').id,
  'res_model': 'account.invoice',
  'context': {'type':'out_invoice', 'default_type': 'out_invoice', 'default_comment': com },
  'target': 'new'
}


Fragen Sie
Writer
Keep Informed
2 Verfolger
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now