OCA / sale-workflow

Odoo Sales, Workflow and Organization
GNU Affero General Public License v3.0
292 stars 1.02k forks source link

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

Open TelmoSuarezConinpe opened 1 year ago

TelmoSuarezConinpe commented 1 year ago

module: sale_procurement_group_by_line version: 15.0

Steps to reproduce

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 commented 11 months ago

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 commented 11 months ago

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 commented 10 months ago

@TelmoSuarezConinpe would you mind reviewing/testing this PR? https://github.com/OCA/sale-workflow/pull/2613

It should solve this issue.