I want to know how can I get the total received and total delivered quantity to be shown on the header of product form
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Comptabilitat
- Inventari
- PoS
- Project
- MRP
This question has been flagged
Hello Suhaib,
There is a compute field called "sales_count" on product.template and product.product model.
class ProductProduct(models.Model):Similar way purchase module also have field called "purchased_product_qty" for product.product and product.template 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
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
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
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Registrar-seRelated Posts | Respostes | Vistes | Activitat | |
---|---|---|---|---|
|
0
de jul. 24
|
2004 | ||
|
1
de març 24
|
2243 | ||
Out of Stock
Solved
|
|
4
de febr. 24
|
5273 | |
|
1
de jul. 23
|
2874 | ||
|
1
de maig 23
|
3535 |
Hello Suhaib,
Have you got a solution for this?
I want to implement the same.
Thanks