Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
3644 Vistas

I want to know how can I get the total received and total delivered quantity to be shown on the header of product form


Avatar
Descartar

Hello Suhaib,
Have you got a solution for this?
I want to implement the same.
Thanks

Mejor respuesta

Hello Suhaib,

There is a compute field called "sales_count" on product.template and product.product model.

class ProductProduct(models.Model):
_inherit = 'product.product'

sales_count = fields.Float(compute='_compute_sales_count', string='Sold')

def _compute_sales_count(self):
r = {}
self.sales_count = 0
if not self.user_has_groups('sales_team.group_sale_salesman'):
return r
date_from = fields.Datetime.to_string(fields.datetime.combine(fields.datetime.now() - timedelta(days=365),
time.min))
done_states = self.env['sale.report']._get_done_states()
domain = [('state', 'in', done_states),
('product_id', 'in', self.ids),
('date', '>=', date_from)]
for group in self.env['sale.report'].read_group(domain, ['product_id', 'product_uom_qty'], ['product_id']):
r[group['product_id'][0]] = group['product_uom_qty']
for product in self:
if not product.id:
product.sales_count = 0.0
continue
product.sales_count = float_round(r.get(product.id, 0), precision_rounding=product.uom_id.rounding)
return r
Similar way purchase module also have field called "purchased_product_qty" for product.product and product.template model.

class ProductProduct(models.Model):
_name = 'product.product'
_inherit = 'product.product'

purchased_product_qty = fields.Float(compute='_compute_purchased_product_qty', string='Purchased')

def _compute_purchased_product_qty(self):
date_from = fields.Datetime.to_string(fields.datetime.now() - timedelta(days=365))
domain = [
('state', 'in', ['purchase', 'done']),
('product_id', 'in', self.ids),
('date_order', '>', date_from)
]
PurchaseOrderLines = self.env['purchase.order.line'].search(domain)
order_lines = self.env['purchase.order.line'].read_group(domain, ['product_id', 'product_uom_qty'], ['product_id'])
purchased_data = dict([(data['product_id'][0], data['product_uom_qty']) for data in order_lines])
for product in self:
if not product.id:
product.purchased_product_qty = 0.0 continue product.purchased_product_qty = float_round(purchased_data.get(product.id, 0), precision_rounding=product.uom_id.rounding)


Thanks & Regards,



CandidRoot Solutions Pvt. Ltd.

Mobile: (+91) 8849036209
Email: info@candidroot.com
Skype: live:candidroot
Web: https://www.candidroot.com
Address: 1229-1230, Iconic Shyamal, Near Shyamal Cross Road, Ahmedabad, Gujarat 380015
    

Avatar
Descartar
Autor

Thanks for the answer, but I know about these fields. These fields comes from SO and PO and not the received or delivered quantities
I want the received and delivered count here

Publicaciones relacionadas Respuestas Vistas Actividad
0
jul 24
1910
1
mar 24
2190
4
feb 24
5216
1
jul 23
2839
1
may 23
3502