odoo 17 validation error on Button Click in Wizard "Please click on the "save" button first"

109 views Asked by At

I have this code for wizard,

from odoo import models, fields

class ShProductBundleWizardLine(models.TransientModel):
    _name = 'sh.product.bundle.wizard.line'
    _description = 'Bundle Wizard Lines'

    wizard_id = fields.Many2one('sh.product.bundle.wizard', 'Wizard ID')
    sh_product_id = fields.Many2one(
        'product.product', 'Product', required=True)
    sh_bundle_quantity = fields.Float("Quantity")
    sh_bundle_uom = fields.Many2one("uom.uom", "Unit Of Measure")
from odoo import models, fields, api


class ShProductBundleWizard(models.TransientModel):
    _name = 'sh.product.bundle.wizard'
    _description = 'Bundle Wizard'

    sh_partner_id = fields.Many2one('res.partner', 'Customer', required=True)
    sh_bundle_id = fields.Many2one(
        'product.template', 'Add Pack / Bundle', required=True, domain=[('sh_is_bundle', '=', True)])
    sh_qty = fields.Float('Quantity', default=1.00, required=True)
    sh_price = fields.Float('Pack / Bundle Price')
    sh_bundle_lines = fields.One2many(
        'sh.product.bundle.wizard.line', 'wizard_id', string='Bundle Lines')

    def action_addBundle(self):
        context = self._context.copy()

        print('inside')
        pass

    @api.model
    def default_get(self, fields):
        print("inside defualt")
        defaults = super(ShProductBundleWizard, self).default_get(fields)
        bundle_products = self.env['product.product'].search([('sh_is_bundle', '=', True)])

        print('bundle_products',bundle_products)

        defaults['sh_bundle_lines'] = [(0, 0, {
            'sh_product_id': product.id,
        }) for product in bundle_products]
        return defaults
<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="sh_product_bundle_wizard_form_view" model="ir.ui.view">
        <field name="name">sh.product.bundle.wizard.form.view</field>
        <field name="model">sh.product.bundle.wizard</field>
        <field name="arch" type="xml">
            <form string="Add Pack / Bundle">
                <group>
                    <group>
                        <field name="sh_partner_id" />
<!--                        <field name="sh_bundle_id" />-->
                    </group>
               <!--     <group>
                        <field name="sh_qty" />
                        <field name="sh_price" />
                    </group>-->
                </group>
                <notebook>
                    <page string="Products">
                        <field name="sh_bundle_lines">
                            <tree editable="bottom" create="0">
                                <field name="sh_product_id"  readonly = "1" />
                                <button name="action_addBundle" string="Add Pack/Bundle" type="object" icon="fa-exchange" help="Add Pack/Bundle to sales line" context="{'create': True}"/>

<!--                                <field name="sh_bundle_quantity" force_save="1" readonly = "1"/>-->
<!--                                <field name="sh_bundle_uom" force_save="1" readonly = "1"/>-->
                            </tree>
                        </field>
                    </page>
                </notebook>
                <footer>
                    <button string="Add Pack/Bundle" name="action_add_pack" type="object" class="btn-primary" />
                   <span class="badge text-wrap">or</span>
                    <button string="Cancel" class="btn btn-primary" special="cancel" />
                </footer>
            </form>
        </field>
    </record>
    <record id="sh_action_add_pack" model="ir.actions.act_window">
        <field name="name">Add Pack/Bundle</field>
        <field name="res_model">sh.product.bundle.wizard</field>
        <field name="view_mode">form</field>
        <field name="view_id" ref="sh_product_bundle_wizard_form_view" />
        <field name="target">new</field>
    </record>
</odoo>

This Wizard is opens in a sale.order model form with a button click "" , Window action code is below :

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <record id="sh_sale_order_form_view" model="ir.ui.view">
        <field name="name">sh.sale.order.form.view</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form" />
        <field name="arch" type="xml">
            <xpath expr="//notebook//page[@name='order_lines']//field[@name='order_line']" position="before">
                <button name="action_bundle_product" string="Add Pack/Bundle" class="oe_highlight" type="object" />
            </xpath>
        </field>
    </record>
</odoo>

Python side code:


from odoo import models


class ShSaleOrder(models.Model):
    _inherit = 'sale.order'

    def action_bundle_product(self):
        if self:
            return {
                'name': 'Add Pack/Bundle',
                'type': 'ir.actions.act_window',
                'view_type': 'form',
                'view_mode': 'form',
                'res_model': 'sh.product.bundle.wizard',
                'target': 'new',
                'context': {'default_sh_partner_id': self.partner_id.id, },
            }

when I click on "Add Pack/Bundle" in sale.order form view, it loads the wizard with data and button successfully as required, when I click on any button in the Wizard's Tree view "action_addBundle" is not called but a message from odoo displayed from its client-side library as "Please click on the "save" button first" , There no backend call made, my main reason to call backend function is to fill the sale.order.lines from this Wizard button with same value value of wizard line

0

There are 0 answers