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
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
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
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
0
thg 7 24
|
2185 | ||
|
1
thg 3 24
|
2376 | ||
Out of Stock
Đã xử lý
|
|
4
thg 2 24
|
5569 | |
|
1
thg 7 23
|
3032 | ||
|
1
thg 5 23
|
3723 |
Hello Suhaib,
Have you got a solution for this?
I want to implement the same.
Thanks