I'm kinda new to odoo and I'm trying to get Company wise purchase order name, vendor name, name of the prooduct and it's scheduled date based on the condition where scheduled date = a particular date eg: 30-04-2021, status= purchase or done and Quantity - received_qty = 0 (ie., products which are not fully received).
Here, is the function that I wrote.
Note: I haven't added the quantity condition yet.
def get_purchase_order_expiry_date(self):
company_list = []
current_date = datetime.today().replace(microsecond=0)
curr_start_date = current_date.replace(hour=00, minute=00, second=00, microsecond=0)
curr_end_date = current_date.replace(hour=23, minute=59, second=59, microsecond=0)
for rec in self:
lang = self.env.context.get("lang")
langs = self.env['res.lang']
if lang:
langs = self.env['res.lang'].search([("code", "=", lang)])
format_date = langs.date_format or '%B-%d-%Y'
current_date2 = str(current_date)
new_date = datetime.strptime(current_date2, DEFAULT_SERVER_DATETIME_FORMAT) + relativedelta(
days=rec.expiry_offset)
new_start_date = new_date.replace(hour=00, minute=00, second=00)
new_end_date = new_date.replace(hour=23, minute=59, second=59)
company_ids = self.env['res.company'].search([])
for company in company_ids:
expiring_po = self.env['purchase.order'].search(
['&', '|', '&', ('date_planned', '>=', str(new_start_date)),
('date_planned', '<=', str(new_end_date)),
('date_planned', '>=', str(curr_start_date)),
('date_planned', '<=', str(curr_end_date)),
('state', 'in', ['purchase', 'done']),
('company_id', '=', company.id)])
if expiring_po:
po_list = []
for p_orders in expiring_po:
due_date = datetime.strptime(p_orders.date_planned, DEFAULT_SERVER_DATETIME_FORMAT).strftime(
format_date)
po_list.append({'product_name': p_orders.product_id.name,
'po_name': p_orders.name,
'vendor_name': p_orders.partner_id.name,
'scheduled_date': due_date})
if po_list:
company_list.append({'company_name': company.name,
'expiring_po': po_list})
return company_list
These are the fields in the order line of purchase order.