Mohamed Fouad
Mohamed Fouad

Reputation: 526

how to get records into wizard from the current form view in odoo?

i have added a button called return in purchase order form view which display a wizard view that i can get products to it to be returned, all is working good, but i need to know how can i get the product of self PO lines,

class returnfromorder(models.TransientModel):
_name = 'returnfromorder'


picking_id = fields.Many2one('stock.picking')
product_return_moves = fields.One2many('stock.return.picking.line', 'wizard_id', 'Moves')
move_dest_exists = fields.Boolean('Chained Move Exists', readonly=True)
original_location_id = fields.Many2one('stock.location')
parent_location_id = fields.Many2one('stock.location')
location_id = fields.Many2one(
    'stock.location', 'Return Location',
    domain="['|', ('id', '=', original_location_id), ('return_location', '=', True)]")

@api.multi
def buto(self):
    products=self.env['purchase.order'].order_line
    for product in products.search([]):
        pro = product.product_id
        print(pro)

i'am using the methode buto in a button in form view so i can test and print the values before working to add them in lines

here is XML

    <!-- Inherit Form View to Modify it -->
    <record id="wizard_return_form" model="ir.ui.view">
        <field name="name">wizard.return.form</field>
        <field name="model">returnfromorder</field>
        <field name="arch" type="xml">
            <form string="return">
                <sheet>
                    <group>
                        <field name="picking_id"/>
                        <field name="product_return_moves"/>
                        <field name="move_dest_exists"/>
                        <field name="original_location_id"/>
                        <field name="parent_location_id"/>
                        <field name="location_id"/>
                        <button name="buto" class="oe_highlight" type="object" string="ObjectButton"/>
                    </group>
                </sheet>
                <footer>
                    <button string="Skip" class="btn-secondary" special="cancel"/>
                </footer>
            </form>
        </field>
    </record>

    <act_window id="return_wizard"
                name="Add return"
                res_model="returnfromorder"
                view_mode="form"
                target="new"
                view_id="wizard_return_form"
    />

any help will be appreciated

Upvotes: 2

Views: 3347

Answers (1)

Bhavesh Odedra
Bhavesh Odedra

Reputation: 11143

You can get current record ids in wizard from context.

For example:

self._context.get('active_ids', [])

Afterwards, you can browse those records, like

for purchase in self.env['purchase.order'].browse(self._context.get('active_ids', []))
    XXXXXX
    execute your logic

Upvotes: 2

Related Questions