Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5024 Lượt xem

Hi, Im triying to get from stock_moves the serial numbers that are available (( in + internal) not in (out)). the serial number is the name from the table stock.production.lot. I added two variables too needed for some pourposes (numero_ticket, numero_series)

well, I created one page in the product_normal_form_view, and inside this one, I want to show the serial numbers available (internal + in)-out. This is my class:

The problem is that I have no idea how to get the active product_id from view to use it on a query. Heres my poor code :):

class product_product(osv.osv):
    _name = "product.product"
    _inherit = "product.product"

    def _get_lines(self, cr, uid, ids,fields, arg, context):

        product = self.browse(cr,uid,id)
        lines={}
        sql = '''
            SELECT DISTINCT c.name, b.numero_ticket, b.numero_guia
                        FROM stock_move b, stock_picking a,stock_production_lot c
                        WHERE (a.id=b.picking_id)AND ((a.type='internal') OR (a.type='in'))AND(b.prodlot_id=c.id) AND (b.product_id=%s) AND c.name NOT IN
                            (SELECT c.name
                            FROM stock_move b, stock_picking a, stock_production_lot c
                            WHERE (a.id=b.picking_id)AND(a.type='out') AND (b.prodlot_id=c.id) AND (b.product_id=%s))''' % (product,product)
        cr.execute(sql)

        lines=cr.fetchall()

        return lines

    _columns = {

        'lineas':fields.function(_get_lines,'lineas',type="char")
    }

product_product()

and my view:

 <record model="ir.ui.view" id="product_normal_form_view">
            <field name="name">product.product.form</field>
            <field name="model">product.product</field>
            <field name="inherit_id" ref="product.product_normal_form_view"/>
                <field name="type">form</field>
                <field name="arch" type="xml">
                        <notebook position="inside">
                            <page string="N serie">
                                <field colspan="4" name="lineas"/><!-- nolabel="1" widget="one2many_list" > -->
                                    <!--<tree string="Lineas">
                                        <field name="prodlot_id"/>
                                        <field name="numero_ticket"/>
                                        <field name="numero_guia"/>
                                    </tree>-->

                            </page>
                        </notebook>
            </field>
        </record>

As you can see I have some troubles trying to fetch the result of the query and using it on the view. Every help will be so much appreciated. I think many people has the same problems as me, and I was searching for so long via google, so I think it can be useful for the rest of the comunity.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
ORM Query Search Đã xử lý
7
thg 4 22
14979
1
thg 3 15
7308
0
thg 3 15
4594
1
thg 3 15
9334
1
thg 12 23
20955