Bonjour,
D'après la documentation odoo il est possible d'afficher un champs calculé en utilisant l'attribut store=True, dans le Field odoo. Voici mon code:
Code Python : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 x_payment_amount_com = fields.Monetary( string="Payment amount", store=True, compute='_compute_amount_b',currency_field="currency_id") x_payment_journal_id = fields.Char(string="ID journal", store=True) x_payment_date = fields.Date(string="Date of payments", store=True) x_payment_type = fields.Char(string="Payment Type",store=True) x_view_journal = fields.Char(string="journal view", related ="x_payment_journal_id") @api.one @api.depends('payment_ids','x_amount_surcom','x_payment_amount_com','x_payment_journal_id','x_payment_type','currency_id','x_payment_date','x_payment_type',' x_view_journal ') def _compute_amount_b(self): payments = self.payment_ids amount = self.x_amount_surcom currency=self.currency_id total = 0 for px in payments: for mv in px.move_line_ids : if (mv.account_id.code.startswith('7') and currency.name==px.currency_id.name): self.x_payment_amount_com = px.amount self.x_payment_journal_id=mv.account_id.code self.x_view_journal=mv.account_id.code self.x_payment_date = px.payment_date self.x_payment_type = px.payment_method_code _logger.info(msg=" mv code "+str(mv.account_id.code)) _logger.info(msg=" self code "+str(self.x_payment_journal_id)) _logger.info(msg=" amount "+str(px.amount)) _logger.info(msg=" self amount "+str(self.x_payment_amount_com)) _logger.info(msg=" date "+str(px.payment_date)) _logger.info(msg=" self date "+str(self.x_payment_date))
Même si j'ai bien les valeurs correspondants dans le log info je n'arrive pas à afficher ces valeurs dans la vue :
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 <record model="ir.ui.view" id="a_w_2.b_listing_view"> <field name="name"> a_w_2.b_listing_view</field> <field name="model">account.invoice</field> <field name="inherit_id" ref="account.invoice_tree"/> <field name="mode">primary</field> <field name="arch" type="xml"> <tree > <field name="x_payment_amount_com" string="Montant Paiement"/> <field name="x_payment_journal_id" string="Journal ID" /> <field name="x_payment_date" string="Date de paiement" /> <field name="x_payment_type" string="Type de paiement" /> <field name="x_view_journal" string=" Journal view" /> <field name="payment_ids" widget="many2many_tags" options="{'no_create': True}" context="{'form_view_ref' : 'b_payments_form', 'tree_view_ref' : 'b_payments_tree'}" /> </tree> <xpath expr="//tree" position="attributes"> <attribute name="default_order">user_id asc</attribute> </xpath> <xpath expr='//tree' position='attributes'> <attribute name="create">false</attribute> </xpath> </field> </record>
J'ai (il me semble ) suivi la doc correctement mais il y a peut être un fonctionnement qui m'échappe ?
Y a t- il une autre façon pour afficher les champs calculés?
cdt
Partager