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账号

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

    添加新的total quantity

    Odoo 新手求助
    2
    9
    4413
    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.
    • M
      mrchengjin last edited by

      sale.py
      from osv import osv,fields
       
      class sale_order(osv.osv):
      _name='sale.order'
      _inherit = 'sale.order'

      def amount_all(self, cr, uid, ids, field_name, arg, context=None):
      res = {}
      for order in self.browse(cr, uid, ids, context=context):
      res[order.id] = {
      'total_quantity': 0.0,
      }
      val2 = 0.0
      for line in order.order_line:
      val2 += line.product_uom_qty
      res[order.id]['total_quantity'] = val2
      return res

      def _get_order(self, cr, uid, ids, context=None):
      result = {}
      for line in self.pool.get('sale.order.line').browse(cr, uid, ids, context=context):
      result[line.order_id.id] = True
      return result.keys()

      _columns = {
       
      'total_quantity':fields.function(amount_all,type='float',string='Total Quantity',
      store={
      'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
      'sale.order.line': (_get_order, ['price_unit', 'tax_id', 'discount', 'product_uom_qty'], 10),
      },
      multi='sums', help="The total quantity", track_visibility='always'),
      }
             
      sale_order() 

      sale_view.xml
      <xpath expr="//field[@name='amount_untaxed']" position="before">
      <field name="total_quantity" />
      </xpath>

      新添加的total_quantity field 回值显示0.00. 无报错,问题出在那里,请有经验的解答下, 求的值是全订单的物品数量值.谢谢

      1 Reply Last reply Reply Quote 0
      • digitalsatori
        digitalsatori 管理员 last edited by

        amount_all的返回值的数据格式错误。应该返回一个id-value的mapping。

        res[order.id]=value
        

        【上海先安科技】(tony AT openerp.cn)

        1 Reply Last reply Reply Quote 0
        • M
          mrchengjin last edited by

          添加return res[order.id]=value? 还是别的,请解释下,不太明白,谢谢

          1 Reply Last reply Reply Quote 0
          • digitalsatori
            digitalsatori 管理员 last edited by

            看来代码不是你写得 😉


            你现在返回的值是这样的:{ORDER_ID:{'total_quantity': QUANTITY_VAL},...}
            需要返回的值应该是这样的: {ORDER_ID: QUANTITY_VAL, ...}

            【上海先安科技】(tony AT openerp.cn)

            1 Reply Last reply Reply Quote 0
            • M
              mrchengjin last edited by

              回的值还是不对,还是0.00,请指点

              1 Reply Last reply Reply Quote 0
              • digitalsatori
                digitalsatori 管理员 last edited by

                [quote author=mrchengjin link=topic=16566.msg28759#msg28759 date=1408342762]
                回的值还是不对,还是0.00,请指点
                [/quote]


                把你修改后的代码,贴出来,大家看看。修改后要重启服务器。


                另外, 你这样的需求可以不用写function字段的,参考一下“会计凭证”表单中“分录明细”部分下面的“贷方合计”,“借方合计”。只要在销售订单表单视图中,订单行明细中 'product_uom_qty' 字段中添加“sum”属性就可以了。

                【上海先安科技】(tony AT openerp.cn)

                1 Reply Last reply Reply Quote 0
                • M
                  mrchengjin last edited by

                  sale.py
                  # -- coding: utf-8 --

                  from osv import osv,fields
                   
                  class sale_order(osv.osv):
                  _name='sale.order'
                  _inherit = 'sale.order'

                  def qty_all(self, cr, uid, ids, field_name, arg, context=None):
                  res = {}
                  for order in self.browse(cr, uid, ids, context=context):
                  res[order.id] = {
                  'total_quantity': 0.0,
                  }
                  val2 = 0.0
                  for line in order.order_line:
                  val2 += line.product_uom_qty
                  res[order.id] = val2
                  return res

                  def _get_order(self, cr, uid, ids, context=None):
                  result = {}
                  for line in self.pool.get('sale.order.line').browse(cr, uid, ids, context=context):
                  result[line.order_id.id] = True
                  return result.keys()

                  _columns = {

                  'total_quantity':fields.function(qty_all,type='float',string='Total Quantity',
                  store={
                  'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
                  'sale.order.line': (_get_order, ['product_uom_qty'], 10),
                  }, help="The total quantity", track_visibility='always'),
                  }

                  经修改和测试后能用的代码,谢谢大家指导.
                  6.1测试成功,如果已经建立的表单,需要修改表单里的产品数量(任意)并保存才能显示新的计算产品量

                  1 Reply Last reply Reply Quote 0
                  • digitalsatori
                    digitalsatori 管理员 last edited by

                    &nbsp; <br />for order in self.browse(cr, uid, ids, context=context):&nbsp; &nbsp; &nbsp; &nbsp;  <br />&nbsp; &nbsp; res[order.id] = {&#039;total_quantity&#039;: 0.0,}
                    


                    这段代码就不需要了。

                    【上海先安科技】(tony AT openerp.cn)

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