|
@@ -0,0 +1,58 @@
|
|
|
|
+
|
|
|
|
+import math
|
|
|
|
+
|
|
|
|
+from datetime import datetime, timedelta
|
|
|
|
+import time
|
|
|
|
+from openerp.osv import fields, osv
|
|
|
|
+from openerp.tools.translate import _
|
|
|
|
+from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
|
|
|
|
+
|
|
|
|
+class product_product(osv.Model):
|
|
|
|
+ _inherit = 'product.product'
|
|
|
|
+
|
|
|
|
+ def _pos_count(self, cr, uid, ids, field_name, arg, context=None):
|
|
|
|
+ r = dict.fromkeys(ids, 0)
|
|
|
|
+ domain = [
|
|
|
|
+ ('product_id', 'in', ids),
|
|
|
|
+ ]
|
|
|
|
+ for group in self.pool['report.pos.order'].read_group(cr, uid, domain, ['product_id','product_qty'], ['product_id'], context=context):
|
|
|
|
+ r[group['product_id'][0]] = group['product_qty']
|
|
|
|
+ return r
|
|
|
|
+
|
|
|
|
+ def action_view_pos(self, cr, uid, ids, context=None):
|
|
|
|
+ result = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'point_of_sale.action_pos_order_line', raise_if_not_found=True)
|
|
|
|
+ result = self.pool['ir.actions.act_window'].read(cr, uid, [result], context=context)[0]
|
|
|
|
+ result['domain'] = "[('product_id','in',[" + ','.join(map(str, ids)) + "])]"
|
|
|
|
+ return result
|
|
|
|
+
|
|
|
|
+ _columns = {
|
|
|
|
+ 'pos_count': fields.function(_pos_count, string='# Pos', type='integer'),
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+class product_template(osv.Model):
|
|
|
|
+ _inherit = 'product.template'
|
|
|
|
+
|
|
|
|
+ def _pos_count(self, cr, uid, ids, field_name, arg, context=None):
|
|
|
|
+ res = dict.fromkeys(ids, 0)
|
|
|
|
+ for template in self.browse(cr, uid, ids, context=context):
|
|
|
|
+ res[template.id] = sum([p.pos_count for p in template.product_variant_ids])
|
|
|
|
+ return res
|
|
|
|
+
|
|
|
|
+ def action_view_pos(self, cr, uid, ids, context=None):
|
|
|
|
+ act_obj = self.pool.get('ir.actions.act_window')
|
|
|
|
+ mod_obj = self.pool.get('ir.model.data')
|
|
|
|
+ product_ids = []
|
|
|
|
+ for template in self.browse(cr, uid, ids, context=context):
|
|
|
|
+ product_ids += [x.id for x in template.product_variant_ids]
|
|
|
|
+ result = mod_obj.xmlid_to_res_id(cr, uid, 'point_of_sale.action_pos_order_line',raise_if_not_found=True)
|
|
|
|
+ result = act_obj.read(cr, uid, [result], context=context)[0]
|
|
|
|
+ result['domain'] = "[('product_id','in',[" + ','.join(map(str, product_ids)) + "])]"
|
|
|
|
+ return result
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ _columns = {
|
|
|
|
+ 'pos_count': fields.function(_pos_count, string='# Pos', type='integer'),
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|