This question has been flagged
2 Replies
2991 Views

Hi,

    we are working with a standar Odoo 11 POS module, we use two payment methods (cash and card). We know that a pos order can be paid with both methods (50% - 50% por example), but we just need to show in the order header the first payment method used.

Payment lines are stored in the "statement_ids" of "pos.order", and the field we need to show is "journal_id".

We tried:

1. adding a field in the header "<field name="statement_ids.journal_id"/>

2. adding a field in the header "<field name="statement_ids[0].journal_id"/>

3. adding a new field in the pos.order model using the advanced properties (dependencies, etc.)

But no one seems to work.

Another good option could be to simple be able to add a filter in the "Sales Details" report to show the standard information filtered by the payment method. My customer needs to know the information displayed there (productos sold in a period) but they need to know the payment method used (taking into account they only use one method by order).

Hope someone could help me.

Thanks.

Avatar
Discard
Best Answer

Hi,

I would suggest you to add a new computed field which would be set with statement_ids[0].journal_id in the compute function.

first_journal_id = fields.Many2one('account.journal', compute='_compute_first_journal', store=True)

@api.depends('statement_ids', 'statement_ids.journal_id')
def _compute_first_journal(self):

    for record in self:

        record.first_journal_id = record.statement_ids[0].journal_id.id

Then you can use the new field in the view simply like usual field:

<field name="first_journal_id"/>


PS: be aware - I haven't tested that piece of code above, so please use it as a pre-sample :)

PSPS: if you like the answer - please don't forget to upvote it :) Thanks!

Avatar
Discard
Author Best Answer

Hi volodymyr,

    seems to be a good aproach but still didn't reach to solve it, surely is because I'm a functional consultant and only know a bit of technical issues.

Created a new field "x_first_journal_id", type "text".
Base properties: readonly "true", store "false", all others "false"
Advanced properties: dependencies "statement_ids", compute:

x_first_journal_id = fields.Many2one('account.journal', compute='_compute_first_journal', store=True)
@api.depends('statement_ids', 'statement_ids.journal_id')
def _compute_first_journal(self):
    for record in self:
        record.x_first_journal_id = record.statement_ids[0].journal_id.id

Saves OK but when I display in a form I get this error:

File "/usr/lib/python3/dist-packages/odoo/tools/safe_eval.py", line 189, in assert_valid_codeobj
    raise ValueError("forbidden opcode(s) in %r: %s" % (expr, ', '.join(opname[x] for x in codes)))
ValueError: forbidden opcode(s) in 'lambda': STORE_ATTR

Tried:
1. changing "store=true"
2. changing the last line for: "record.x_first_journal_id = record.statement_ids[0].journal_id", because I'm not sure about the ".id"

But get the same error, I don't still feel comfortable with the technical-code part. Any idea with this error?.
Thanks for your help ! 



Avatar
Discard

Carlos, I would advise to use a bit of technical support for this issue, because the way you've done it is not correct.