[19.0][ADD] purchase_auto_bill_on_receipt#3075
Conversation
bd429fd to
e97aff1
Compare
smorita7749
left a comment
There was a problem hiding this comment.
Code and functional review: LGTM
e97aff1 to
102a01f
Compare
| picking._auto_create_vendor_bill() | ||
| return res | ||
|
|
||
| def _auto_create_vendor_bill(self): |
There was a problem hiding this comment.
Can we move this above buttom_validate?
|
|
||
| block_auto_bill = fields.Boolean( | ||
| help="When enabled, suppresses automatic bill creation on receipt " | ||
| "for this order, regardless of product or category settings.", |
There was a problem hiding this comment.
Please update this to reflect the recent change.
| 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) |
There was a problem hiding this comment.
Try handling these steps with cron + _trigger() instead.
| 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 | ||
| ) |
There was a problem hiding this comment.
| 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 | |
| ) |
| invoice_lines.append(Command.create(section_vals)) | ||
| sequence += 1 | ||
| pending_section = None | ||
| line_vals = line._prepare_account_move_line() |
There was a problem hiding this comment.
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.
102a01f to
2e4edf2
Compare
2e4edf2 to
1eb0690
Compare
| line_vals["sequence"] = sequence | ||
| line_vals["quantity"] = qty | ||
| invoice_lines.append(Command.create(line_vals)) |
There was a problem hiding this comment.
Very minor point but should be in this order.
| 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() |
There was a problem hiding this comment.
To be safe.
| 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 |
There was a problem hiding this comment.
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.
This module automatically creates and posts a Vendor Bill when a purchase receipt is validated.
@qrtl QT6796