Navigation

    Odoo 中文社区

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Popular
    • Users
    • Groups

    Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

    由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

    本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

    开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

    如果您登录系统碰到问题,请在微信公众号留言:

    库存明细报表的实现

    Odoo 开发与实施交流
    5
    7
    5673
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Q
      qdfulee last edited by

      OE当前的功能里,查询库存要么是所有产品所有库位一张表,要么是一个产品在不同库位的数量分布,无法在一张表上实现多个产品多个库位的明细。
      于是就有了如下的代码:

      # -*- coding: utf-8 -*-<br />from openerp.osv import osv,fields<br />from lxml import etree<br />from openerp import tools<br /><br /><br />class product_product(osv.osv):<br />&nbsp; &nbsp; _inherit = &quot;product.product&quot;<br /><br />&nbsp; &nbsp; def fields_view_get(self, cr, uid, view_id=None, view_type=&#039;form&#039;, context=None, toolbar=False, submenu=False):<br />&nbsp; &nbsp; &nbsp; &nbsp; res = super(product_product, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar=toolbar, submenu=submenu)<br />&nbsp; &nbsp; &nbsp; &nbsp; if context.get(&#039;inventory_list&#039;) == True and view_type == &#039;tree&#039;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loc_obj = self.pool.get(&#039;stock.location&#039;)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; locations = loc_obj.browse(cr, uid, loc_obj.search(cr, uid, [(&#039;child_ids&#039;, &#039;=&#039;, False), (&#039;usage&#039;, &#039;=&#039;, &#039;internal&#039;)]))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; view = etree.fromstring(res&#91;&#039;arch&#039;])<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fields_list = res&#91;&#039;fields&#039;]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for location in locations:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fields_list[tools.ustr(location.id)+&#039;-real&#039;] = {&#039;type&#039;: &#039;float&#039;, &#039;string&#039;: location.name+&#039;-实际库存&#039;}<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fields_list[tools.ustr(location.id)+&#039;-virtual&#039;] = {&#039;type&#039;: &#039;float&#039;, &#039;string&#039;: location.name+&#039;-账面库存&#039;}<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; etree.SubElement(view, &#039;field&#039;, {&#039;name&#039;: tools.ustr(location.id)+&#039;-real&#039;})<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; etree.SubElement(view, &#039;field&#039;, {&#039;name&#039;: tools.ustr(location.id)+&#039;-virtual&#039;})<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res&#91;&#039;arch&#039;] = etree.tostring(view)<br />&nbsp; &nbsp; &nbsp; &nbsp; return res<br /><br />&nbsp; &nbsp; def read(self, cr, uid, ids, fields=None, context=None, load=&#039;_classic_read&#039;):<br />&nbsp; &nbsp; &nbsp; &nbsp; result = super(product_product, self).read(cr, uid, ids, fields=fields, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; if context.get(&#039;inventory_list&#039;) == True:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; locations = &#91;]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for field in fields:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s = field.split(&#039;-&#039;)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if len(s) == 2:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if s[1] == &#039;real&#039;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; locations.append(int(s[0]))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i = 0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for id in ids:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for location in locations:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context&#91;&#039;location&#039;] = location<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; val = super(product_product, self).read(cr, uid, id, &#91;&#039;qty_available&#039;, &#039;virtual_available&#039;], context, )<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result[i][tools.ustr(location)+&#039;-real&#039;] = val&#91;&#039;qty_available&#039;]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result[i][tools.ustr(location)+&#039;-virtual&#039;] = val&#91;&#039;virtual_available&#039;]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i += 1<br />&nbsp; &nbsp; &nbsp; &nbsp; return result
      



      实现的效果附件


      1 Reply Last reply Reply Quote 0
      • C
        ccdos last edited by

        谢谢分享,

        又学了一招

        1 Reply Last reply Reply Quote 0
        • N
          nmglyy last edited by

          这个是怎么用啊。。没看懂

          1 Reply Last reply Reply Quote 0
          • Q
            qq342406169 last edited by

            能否讲解下怎么用呢

            1 Reply Last reply Reply Quote 0
            • Q
              qdfulee last edited by

              后台代码在附件中。说明下,前台显示的二级表头不是我做的,不能上传,见谅。
              目前这个版本的效率不高,希望高手能优化下。

              模块设计思路:

              1、库存明细表是通过 fields_view_get 动态生成的。
              2、不同库位的库存根据系统stock里product.product 中的字段 qty_available,virtual_available 读出。这两个字段的值是依据context里不同库位读出。我是通过这个功能循环产品id和库位id读出的。(这个方法挺笨的)
              3、功能入口通过向导进入。向导生成的菜单如下图:
              [attachimg=2]

              如果安装出错,可能需要把 product.py里 fields_view_get()中下几句代码:
              etree.SubElement(view, 'field', {'name': tools.ustr(location.id)+'-real', 'th_string':location.name, 'colspan':'2'})
              etree.SubElement(view, 'field', {'name': tools.ustr(location.id)+'-virtual','colspan':'1'})
              etree.SubElement(view, 'field', {'name': 'qty_available', 'string': u'实际库存', 'th_string': u'汇总', 'colspan':'2'})
              etree.SubElement(view, 'field', {'name': 'virtual_available', 'string': u'账面库存', 'colspan':'1'})
              中的'th_string' 和'colspan' 标签去掉。

              1 Reply Last reply Reply Quote 0
              • 3
                387912318 last edited by

                感谢分享!

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post