Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
4946 Widoki

Hi all

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

Awatar
Odrzuć
Najlepsza odpowiedź

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>


Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
3
sie 25
2731
1
maj 25
2691
1
kwi 25
3681
1
kwi 25
4534
1
kwi 25
1998