Skip to Content
Menu
This question has been flagged


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


Avatar
Discard
Best Answer

Hi,

Using the active_ids inside the context you can get the values from the record.

purchase_ids = self.env.context.get('active_ids', [])
purchase_rec = self.env['purchase.order'].browse(purchase_ids)

Thanks

Avatar
Discard
Author

@api.multi

def buto(self):

purchase_ids = self.env.context.get('active_ids', [])

products=self.env['purchase.order'].browse(purchase_ids).order_line

for product in products.browse(self.env.context.get('active_id')):

pro = product.product_id

print(pro)

this didn't get the self product in PO

purchase_rec =self.env['purchase.order'].browse(purchase_ids)

for purchase in purchas_rec:

for po_line in purchase.order_line:

Related Posts Replies Views Activity
1
Oct 24
144
2
Sep 20
5035
1
Sep 19
5339
2
Sep 23
2920
2
Sep 22
3254