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