Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
4964 Zobrazení

Hi all

I'm trying to add a button near the sale order line in odoo 16 

Avatar
Zrušit
Nejlepší odpověď

Hi,

are you trying to add button in sale order line[for each line]? if yes, try this code

<record id="view_order_form" model="ir.ui.view">
 
  <field name="name">order.view.form.inherit</field>
 
  <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">
      <xpath expr="//page[@name='order_lines']//tree" position="inside">
        <button string="test" name="method_name" type="object" class="oe_highlight"/>
      </xpath>
    </field>


</record>


Avatar
Zrušit
Nejlepší odpověď

In Odoo 16, you can add a button near the sale order line by creating a new widget and adding it to the sale order line form view. Here's an example of how this can be done:

  1. Create a new widget: In your custom module, create a new JavaScript file and define a new widget that inherits from the instance.web.form.FieldChar class. You can define the button and its functionality in the start method of the widget.
odoo.define('module_name', function (require) {
    "use strict";
    var core = require('web.core');
    var FormView = require('web.FormView');
    var FormField = require('web.form_common');

    var MyButton = FormField.FieldChar.extend({
        template: 'MyButton',
        events: {
            'click button': '_onButtonClick',
        },
        start: function() {
            this._super();
            this.$el.prepend('');
        },
        _onButtonClick: function() {
            console.log('Button clicked');
            // add your functionality here
        },
    });
    core.form_widget_registry.add('my_button', MyButton);
});
  1. Create a new template: Create a new XML template file in your custom module, and define the template for the new widget.
    
  1. Add the widget to the sale order line form view: In your custom module, create a new XML file and inherit the sale order line form view. Add the new widget to the form view by using the tag and specifying the widget attribute as "my_button".
    Sale Order Line Form
    sale.order.line
    
    
        
            
        
    

    
    
        
            
        
    


This is just a basic example, you can customize it according to your need. You can use the position attribute in the xpath to specify where the button should be placed.

You'll need to restart the Odoo server and upgrade your custom module after making these changes to see the button on the Sale Order Line form view.

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
3
srp 25
2740
1
kvě 25
2697
1
dub 25
3688
1
dub 25
4544
1
dub 25
2001