Questo sito utilizza cookie per le proprie funzionalità e per inviarti pubblicità e servizi in linea con le tue preferenze. Chiudendo questo banner, scorrendo questa pagina o cliccando qualunque suo elemento acconsenti all’uso dei cookie.

Accedendo al link http://www.odoo-italia.org/index.php/home/cookie-policy puoi leggere in dettaglio le modalità di trattamento dei cookie da parte dell'Associazione Odoo Italia.

Benvenuto, Ospite
Nome utente: Password: Ricordami
Ricordati di dichiarare la versione di Odoo a cui riferisce la domanda
  • Pagina:
  • 1
  • 2
  • 3

ARGOMENTO: parent in context

parent in context 5 Anni 3 Mesi fa #14023

  • alex_cam
  • Avatar di alex_cam
  • Offline
  • Expert Boarder
  • Messaggi: 153
  • Ringraziamenti ricevuti 2
  • Karma: 1
Ciao a tutti,
sull'ordine di vendita, dove controlla il cambiamento del prodotto ho questo:
<field name="product_id" 
context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}" 
groups="base.group_user"
on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False, context)"/>
Che funzione ha "parent"? Come funziona?

In pratica vorrei mettere nel context di "product_id" un altro campo che sta sulla testata. Come posso fare?
Grazie a tutti
Ciao
Alessandro Camilli
www.openforce.it
L\'Amministratore ha disattivato l\'accesso in scrittura al pubblico.

parent in context 5 Anni 3 Mesi fa #14024

  • NicoTheBrush
  • Avatar di NicoTheBrush
  • Offline
  • Platinum Boarder
  • Messaggi: 1952
  • Ringraziamenti ricevuti 156
  • Karma: 46
Usando parent :)
non ho sottomano l'xml della videata però immagino che product_id sia un campo figlio di un campo one2many della videata principale, grazie all'oggetto parent, da dove ti trovo (videate embedded), puoi raggiungere tutti i campi che sono presenti nella videata principale, vedi parent.pricelist_id che preleva il listino settato sul padre
L\'Amministratore ha disattivato l\'accesso in scrittura al pubblico.

parent in context 5 Anni 3 Mesi fa #14025

  • alex_cam
  • Avatar di alex_cam
  • Offline
  • Expert Boarder
  • Messaggi: 153
  • Ringraziamenti ricevuti 2
  • Karma: 1
Grazie Nico,
volevo approfittare x chiederti un'altra cosa:
immagino che product_id sia un campo figlio di un campo one2many della videata principale
immagini bene.

è possibile cambiare il context di product_id con xparth in questo modo?
<xpath expr="//page[@string='Order Lines']/field/form/group/group/field[@name='product_id']" position="attributes">
					<attribute name="context">{....}</attribute>
				</xpath>
Ci ho provato in tutti i modi, ma sembra non avere effetto. Poi cercando la documentazione trovo poco nulla..quindi probabilmente sto sbagliando approccio.
In pratica ho aggiunto un campo salesman_pricelist in testata dell'ordine e seguendo la logica vorrei metterlo nel context di product_id con "parent.salesman_pricelist"

Grazie ancora x la disponibilità!!
Alessandro Camilli
www.openforce.it
L\'Amministratore ha disattivato l\'accesso in scrittura al pubblico.

parent in context 5 Anni 3 Mesi fa #14035

  • NicoTheBrush
  • Avatar di NicoTheBrush
  • Offline
  • Platinum Boarder
  • Messaggi: 1952
  • Ringraziamenti ricevuti 156
  • Karma: 46
Mi sembra corretto, puoi postare tutto il tuo file XML così vedo anche i riferimenti di inherit?
L\'Amministratore ha disattivato l\'accesso in scrittura al pubblico.

parent in context 5 Anni 3 Mesi fa #14037

  • alex_cam
  • Avatar di alex_cam
  • Offline
  • Expert Boarder
  • Messaggi: 153
  • Ringraziamenti ricevuti 2
  • Karma: 1
l'xml di sale_order:
<record id="view_order_form" model="ir.ui.view">
            <field name="name">sale.order.form</field>
            <field name="model">sale.order</field>
            <field name="arch" type="xml">
                <form string="Sales Order" version="7.0">
                    <header>
                        <button name="invoice_recreate" states="invoice_except" string="Recreate Invoice" groups="base.group_user"/>
                        <button name="invoice_corrected" states="invoice_except" string="Ignore Exception" groups="base.group_user"/>
                        <button name="action_quotation_send" string="Send by Email" type="object" states="draft" class="oe_highlight" groups="base.group_user"/>
                        <button name="action_quotation_send" string="Send by Email" type="object" states="sent" groups="base.group_user"/>
                        <button name="print_quotation" string="Print" type="object" states="draft" class="oe_highlight" groups="base.group_user"/>
                        <button name="print_quotation" string="Print" type="object" states="sent" groups="base.group_user"/>
                        <button name="action_button_confirm" states="draft" string="Confirm Sale" type="object" groups="base.group_user"/>
                        <button name="action_button_confirm" states="sent" string="Confirm Sale" class="oe_highlight" type="object" groups="base.group_user"/>
                        <button name="action_view_invoice" string="View Invoice" type="object" class="oe_highlight"
                            attrs="{'invisible': [('invoice_exists', '=', False)]}" groups="base.group_user"/>
                        <button name="%(action_view_sale_advance_payment_inv)d" string="Create Invoice"
                            type="action" states="manual" class="oe_highlight" groups="base.group_user"/>
                        <button name="copy_quotation" states="cancel" string="New Copy of Quotation" type="object"/>
                        <button name="cancel" states="draft,sent" string="Cancel" groups="base.group_user"/>
                        <button name="action_cancel" states="manual,progress" string="Cancel" type="object" groups="base.group_user"/>
                        <button name="invoice_cancel" states="invoice_except" string="Cancel" groups="base.group_user"/>
                        <field name="state" widget="statusbar" statusbar_visible="draft,sent,invoiced,done" statusbar_colors='{"invoice_except":"red","waiting_date":"blue"}'/>
                </header>
                <sheet>
                    <h1>
                        <label string="Quotation " attrs="{'invisible': [('state','not in',('draft','sent'))]}"/>
                        <label string="Sales Order " attrs="{'invisible': [('state','in',('draft','sent'))]}"/>
                        <field name="name" class="oe_inline" readonly="1"/>
                    </h1>
                    <group>
                        <group>
                            <field name="partner_id" on_change="onchange_partner_id(partner_id, context)" domain="[('customer','=',True)]" context="{'search_default_customer':1, 'show_address': 1}" options='{"always_reload": True}'/>
                            <field name="partner_invoice_id" groups="sale.group_delivery_invoice_address" context="{'default_type':'invoice'}"/>
                            <field name="partner_shipping_id" groups="sale.group_delivery_invoice_address" context="{'default_type':'delivery'}"/>
                            <field name="project_id" context="{'partner_id':partner_id, 'pricelist_id':pricelist_id, 'default_name':name, 'default_type': 'contract'}" groups="sale.group_analytic_accounting" domain="[('type','in',['view','normal','contract'])]"/>
                        </group>
                        <group>
                            <field name="date_order"/>
                            <field name="shop_id" groups="base.group_no_one" on_change="onchange_shop_id(shop_id, context)" widget="selection"/>
                            <field name="client_order_ref"/>
                            <field domain="[('type','=','sale')]" name="pricelist_id" groups="product.group_sale_pricelist" on_change="onchange_pricelist_id(pricelist_id,order_line)"/>
                            <field name="currency_id" invisible="1"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="Order Lines">
                            <field name="order_line">
                                <form string="Sales Order Lines" version="7.0">
                                    <header groups="base.group_user">
                                        <button name="%(action_view_sale_order_line_make_invoice)d" states="confirmed" string="Invoice" type="action" icon="terp-document-new"/>
                                        <field name="state" widget="statusbar" statusbar_visible="draft,confirmed,done" statusbar_colors='{"exception":"red","cancel":"red"}'/>
                                    </header>
                                    <group>
                                        <group>
                                            <field name="state" invisible="1" />
                                            <field name="product_id"
                                                context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
                                                groups="base.group_user"
                                                on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False, context)"/>
                                            <label for="product_uom_qty"/>
                                            <div>
                                                <field
                                                    context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
                                                    name="product_uom_qty" class="oe_inline"
                                                    on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, False, parent.fiscal_position, True, context)"/>
                                                <field name="product_uom" groups="product.group_uom" class="oe_inline oe_no_button"

                                                    on_change="product_uom_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, context)"/>
                                            </div>
                                            <label for="product_uos_qty" groups="product.group_uos"/>
                                            <div groups="product.group_uos">
                                                <field name="product_uos_qty" class="oe_inline"/>
                                                <field name="product_uos" options='{"no_open": True}' class="oe_inline"/>
                                            </div>
                                            <field name="price_unit"/>
                                            <label for="discount" groups="sale.group_discount_per_so_line"/>
                                            <div name="discount" groups="sale.group_discount_per_so_line">
                                                <field name="discount" class="oe_inline"/> %%
                                            </div>
                                        </group>
                                        <group>
                                            <field name="tax_id" widget="many2many_tags" domain="[('parent_id','=',False),('type_tax_use','&lt;&gt;','purchase')]"/>
                                            <field name="type"/>
                                            <field name="th_weight"/>
                                            <!-- we should put a config wizard for these two fields -->
                                            <field name="address_allotment_id"/>
                                        </group>
                                    </group>
                                    <label for="name"/>
                                    <field name="name"/>
                                    <div groups="base.group_no_one">
                                        <label for="invoice_lines"/>
                                        <field name="invoice_lines"/>
                                    </div>
                                </form>
                                <tree string="Sales Order Lines" editable="bottom">
                                    <field name="sequence" widget="handle"/>
                                    <field name="state" invisible="1"/>
                                    <field name="th_weight" invisible="1"/>
                                    <field name="product_id"
                                        context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
                                        groups="base.group_user" 
                                        on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False, context)"/>
                                    <field name="name"/>
                                    <field name="product_uom_qty"
                                        context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
                                        on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, False, parent.date_order, False, parent.fiscal_position, True, context)"/>
                                    <field name="product_uom"
                                        on_change="product_uom_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, False, parent.date_order, context)"
                                        groups="product.group_uom" options='{"no_open": True}'/>
                                    <field name="product_uos_qty" groups="product.group_uos" invisible="1"/>
                                    <field name="product_uos" string="UoS" groups="product.group_uos" invisible="1"/>
                                    <field name="tax_id" widget="many2many_tags" domain="[('parent_id','=',False),('type_tax_use','&lt;&gt;','purchase')]"/>
                                    <field name="price_unit"/>
                                    <field name="discount" groups="sale.group_discount_per_so_line"/>
                                    <field name="price_subtotal"/>
                                </tree>
                            </field>
                            <group class="oe_subtotal_footer oe_right" colspan="2" name="sale_total">
                                <field name="amount_untaxed" widget='monetary' options="{'currency_field': 'currency_id'}"/>
                                <field name="amount_tax" widget='monetary' options="{'currency_field': 'currency_id'}"/>
                                <div class="oe_subtotal_footer_separator oe_inline">
                                    <label for="amount_total" />
                                    <button name="button_dummy"
                                        states="draft,sent" string="(update)" type="object" class="oe_edit_only oe_link"/>
                                </div>
                                <field name="amount_total" nolabel="1" class="oe_subtotal_footer_separator" widget='monetary' options="{'currency_field': 'currency_id'}"/>
                            </group>
                            <div class="oe_clear"/>
                            <field name="note" class="oe_inline" placeholder="Terms and conditions..."/>
                        </page>
                        <page string="Other Information" groups="base.group_user">
                            <group>
                                <group name="sales_person" groups="base.group_user">
                                    <field name="user_id"/>
                                    <field groups="base.group_no_one" name="origin"/>
                                </group>
                                <group name="sale_pay">
                                    <field name="payment_term" widget="selection"/>
                                    <field name="fiscal_position" widget="selection"/>
                                    <field name="company_id" widget="selection" groups="base.group_multi_company"/>
                                </group>
                                <group>
                                    <field name="invoiced"/>
                                    <field name="invoice_exists" invisible="1"/>
                                </group>
                            </group>
                        </page>
                    </notebook>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>
                    <field name="message_ids" widget="mail_thread" placeholder="Share a message..."/>
                </div>
                </form>
            </field>
        </record>

Aggiungo il campo salesman_pricelist alla testata
<record id="salesman_pricelist_sale_order_form" model="ir.ui.view">
			<field name="name">salesman.pricelist.sale.order.form</field>
			<field name="model">sale.order</field>
			<field name="inherit_id" ref="sale.view_order_form"/>
			<field name="arch" type="xml">
			 
				<xpath expr="//page[@string='Other Information']/group/group/field[@name='user_id']" position="after">
				    <newline/>
				    <!-- <field name="salesman_pricelist" attrs="{'required':[('user_id','!=',False)]}" context="{'salesman_pricelist': salesman_pricelist}"
				    	on_change="onchange_salesman_pricelist_id(context)"/> -->
				    <field name="salesman_pricelist" attrs="{'required':[('user_id','!=',False)]}" context="{'salesman_pricelist': salesman_pricelist}"/>
				</xpath>
				
				# load salesman's pricelist
				<xpath expr="//page[@string='Other Information']/group/group/field[@name='user_id']" position="replace">
				    <field name="user_id" on_change="onchange_user_id(user_id, context)"/>
				</xpath>
				
			</field>
		</record>

Cerco di aggiungere il valore di salesman_pricelist nel context di product_id per passarlo in caso di "on_change"
<record id="salesman_commission_sale_order_line_form" model="ir.ui.view">
			<field name="name">salesman.commission.sale.order.line.form</field>
			<field name="model">sale.order</field>
			<field name="inherit_id" ref="sale.view_order_form"/>
			<field name="arch" type="xml">
<xpath expr="//page[@string='Order Lines']/field/form/group/group/field[@name='product_id']" position="attributes">
				    <attribute name="context">{'salesman_pricelist':'parent.salesman_pricelist, 'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}</attribute>
				</xpath>
</field>
		</record> 

Eredito il metodo di "on_change" legato al prodotto sul form della riga
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
            uom=False, qty_uos=0, uos=False, name='', partner_id=False,
            lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None):
        
        import pdb
        pdb.set_trace()
        
        result = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,
            uom, qty_uos, uos, name, partner_id,
            lang, update_tax, date_order, packaging, fiscal_position, flag, context)
        
        if product:
....

ma il context che ricevo in debug rimane sempre lo stesso
{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}
:(
Alessandro Camilli
www.openforce.it
L\'Amministratore ha disattivato l\'accesso in scrittura al pubblico.

parent in context 5 Anni 3 Mesi fa #14038

  • NicoTheBrush
  • Avatar di NicoTheBrush
  • Offline
  • Platinum Boarder
  • Messaggi: 1952
  • Ringraziamenti ricevuti 156
  • Karma: 46
hai esagerato con gli apici:

'salesman_pricelist':'parent.salesman_pricelist

togli quello prima di "parent"
L\'Amministratore ha disattivato l\'accesso in scrittura al pubblico.
  • Pagina:
  • 1
  • 2
  • 3
Tempo creazione pagina: 0.160 secondi

Odoo Italia Associazione - C.F: 94200470485 - Sede: Viale dei Cadorna, 83 - Firenze - Italy

Protected by R Antispam