0

我对 odoo 有点陌生,我正在尝试获取公司明智的采购订单名称、供应商名称、产品名称以及基于预定日期 =特定日期的条件的预定日期,例如:30-04-2021, status= purchase 或 done 和 Quantity - received_qty = 0(即,未完全收到的产品)。

这是我写的函数。

注意:我还没有添加数量条件。

    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

这些是采购订单订单行中的字段。

One2many 字段图像 有人能告诉我哪里出错了吗?

4

0 回答 0