Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sale_procurement_group_by_line: No "Purchases" button in SO from sale_purchase_stock module #2597

Open
TelmoSuarezConinpe opened this issue Jul 7, 2023 · 3 comments

Comments

@TelmoSuarezConinpe
Copy link

module: sale_procurement_group_by_line
version: 15.0

Steps to reproduce

  • Install sale_procurement_group_by_line and sale_purchase_stock
  • Unarchive "Replenish on Order (MTO)" route
    Screenshot 2023-07-06 at 12-54-42 Odoo - Replenish on Order (MTO)
  • Configure product with MTO and Buy.
    Screenshot 2023-07-07 at 11-54-56 Odoo - test MTO
  • Confirm SO with MTO product
  • Check if there is a new PO

Current behavior
In the SO there is no smart button with the related PO
Screenshot 2023-07-07 at 11-37-34 Odoo - S00035

Expected behavior
Additional smart button on the SO with the related PO
Screenshot 2023-07-07 at 11-52-57 Odoo - S00038

@support-skillreso
Copy link

Hello TelmoSuarezConinpe,

Did you find a workaround for this problem ? I have encountered it too and I can't find how to make this work.

Thanks.

@support-skillreso
Copy link

I finally found a correction for this problem. For V14, you need to update the file sale_procurement_group_by_line/model/sale.py

First, you need to import odoo.api :
from odoo import fields, models, **api**

Then you need to override SaleOrder class by adding this code before the SaleOrderLine class definition :

class SaleOrder(models.Model):
    _inherit = 'sale.order'

    @api.depends('order_line.procurement_group_id.stock_move_ids.created_purchase_line_id.order_id', 'order_line.procurement_group_id.stock_move_ids.move_orig_ids.purchase_line_id.order_id')
    def _compute_purchase_order_count(self):
        super(SaleOrder, self)._compute_purchase_order_count()

    def _get_purchase_orders(self):
        return super(SaleOrder, self)._get_purchase_orders() | self.order_line.procurement_group_id.stock_move_ids.created_purchase_line_id.order_id | self.order_line.procurement_group_id.stock_move_ids.move_orig_ids.purchase_line_id.order_id

Explanation :
In module sale_purchase_stock, the method _get_purchase_orders uses the property procurement_group_id of the SaleOrder class to retrieve purchase orders. But when module sale_delivery_split_by_date is installed, procurement_group_id is not used anymore on the SaleOrder. Instead, procurement groups are linked to purchase order lines. So without the fix, _get_purchase_orders returns an empty list of PO.

The fix adds the PO from self.order_line.procurement_group_id the same way that module sale_purchase_stock adds it from self.procurement_group_id. With it, when you confirm a SO the corresponding PO is properly linked and the smart button appears correctly.

I will try to propose a pull request so that this fix is integrated into the module.

@SilvioC2C
Copy link
Contributor

@TelmoSuarezConinpe would you mind reviewing/testing this PR? #2613

It should solve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants