Skip to content

[19.0][ADD] purchase_auto_bill_on_receipt#3075

Open
AungKoKoLin1997 wants to merge 1 commit into
OCA:19.0from
qrtl:19.0-add-purchase_auto_bill_on_receipt
Open

[19.0][ADD] purchase_auto_bill_on_receipt#3075
AungKoKoLin1997 wants to merge 1 commit into
OCA:19.0from
qrtl:19.0-add-purchase_auto_bill_on_receipt

Conversation

@AungKoKoLin1997
Copy link
Copy Markdown
Contributor

@AungKoKoLin1997 AungKoKoLin1997 commented May 26, 2026

This module automatically creates and posts a Vendor Bill when a purchase receipt is validated.

@qrtl QT6796

@OCA-git-bot OCA-git-bot added series:19.0 mod:purchase_auto_bill_on_receipt Module purchase_auto_bill_on_receipt labels May 26, 2026
@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 19.0-add-purchase_auto_bill_on_receipt branch from bd429fd to e97aff1 Compare May 27, 2026 03:24
@AungKoKoLin1997 AungKoKoLin1997 marked this pull request as ready for review May 27, 2026 03:25
Comment thread purchase_auto_bill_on_receipt/models/purchase_order_line.py Outdated
Copy link
Copy Markdown

@smorita7749 smorita7749 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code and functional review: LGTM

Copy link
Copy Markdown
Contributor

@BhaveshHeliconia BhaveshHeliconia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Member

@yostashiro yostashiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review.

Comment thread purchase_auto_bill_on_receipt/models/purchase_order.py Outdated
Comment thread purchase_auto_bill_on_receipt/models/purchase_order.py Outdated
Comment thread purchase_auto_bill_on_receipt/models/product_template.py Outdated
@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 19.0-add-purchase_auto_bill_on_receipt branch from e97aff1 to 102a01f Compare June 8, 2026 03:20
picking._auto_create_vendor_bill()
return res

def _auto_create_vendor_bill(self):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this above buttom_validate?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


block_auto_bill = fields.Boolean(
help="When enabled, suppresses automatic bill creation on receipt "
"for this order, regardless of product or category settings.",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this to reflect the recent change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Comment thread purchase_auto_bill_on_receipt/models/purchase_order.py Outdated
Comment on lines +40 to +59
try:
bill = self._auto_bill_create(picking, eligible_lines)
except Exception as e:
_logger.exception(
"Auto-bill creation failed for PO %s / picking %s",
self.name,
picking.name,
)
self._auto_bill_log_failure(picking, "create", e)
return self.env["account.move"]
try:
bill.action_post()
except Exception as e:
_logger.exception(
"Auto-bill posting failed for PO %s / picking %s / bill %s",
self.name,
picking.name,
bill.name,
)
self._auto_bill_log_failure(picking, "post", e, bill=bill)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try handling these steps with cron + _trigger() instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Comment on lines +32 to +37
received_products = picking.move_ids.product_id
eligible_lines = self.order_line.filtered(
lambda line: line.product_id in received_products
and line.product_id.purchase_method == "receive"
and line.qty_to_invoice > 0
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
received_products = picking.move_ids.product_id
eligible_lines = self.order_line.filtered(
lambda line: line.product_id in received_products
and line.product_id.purchase_method == "receive"
and line.qty_to_invoice > 0
)
eligible_lines = picking.move_ids.purchase_line_id.filtered(
lambda line.product_id.purchase_method == "receive"
and line.qty_to_invoice > 0
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

invoice_lines.append(Command.create(section_vals))
sequence += 1
pending_section = None
line_vals = line._prepare_account_move_line()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get qty from the linked picking and set it here? I think there might be cases where multiple receipts are consolidated into one bill under the current design.

qty = self._get_picking_line_qty(picking, line)
if not qty:
    continue
line_vals["quantity"] = qty

_get_picking_line_qty doesn't exist, so please add it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 19.0-add-purchase_auto_bill_on_receipt branch from 102a01f to 2e4edf2 Compare June 8, 2026 09:08
@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 19.0-add-purchase_auto_bill_on_receipt branch from 2e4edf2 to 1eb0690 Compare June 8, 2026 09:15
Comment on lines +89 to +91
line_vals["sequence"] = sequence
line_vals["quantity"] = qty
invoice_lines.append(Command.create(line_vals))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor point but should be in this order.

Suggested change
line_vals["sequence"] = sequence
line_vals["quantity"] = qty
invoice_lines.append(Command.create(line_vals))
line_vals["quantity"] = qty
invoice_lines.append(Command.create(line_vals))
line_vals["sequence"] = sequence


def _cron_auto_bill(self):
for picking in self.search([("auto_bill_pending", "=", True)]):
picking._auto_create_vendor_bill()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be safe.

Suggested change
picking._auto_create_vendor_bill()
try:
with self.env.cr.savepoint():
picking._auto_create_vendor_bill()
except Exception:
_logger.exception(...)

self.ensure_one()
invoice_vals = self._prepare_invoice()
invoice_vals["invoice_date"] = fields.Date.context_today(
self, picking.date_done
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that it's run by cron user, let's use the timezone of the company's partner. Please document it in the readme as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:purchase_auto_bill_on_receipt Module purchase_auto_bill_on_receipt series:19.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants