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

stock_orderpoint_origin add sale order count for mrp.production #1373

Closed
pumppi opened this issue Feb 17, 2022 · 1 comment
Closed

stock_orderpoint_origin add sale order count for mrp.production #1373

pumppi opened this issue Feb 17, 2022 · 1 comment
Labels
enhancement stale PR/Issue without recent activity, it'll be soon closed automatically.

Comments

@pumppi
Copy link

pumppi commented Feb 17, 2022

Is your feature request related to a problem?
No

Describe the solution you'd like
We been testing stock_orderpoint_origin for adding forecast sale orders to production sale orders smart button.
We did a small, maybe little bit dirty fix to stock_orderpoint_origin for calculating sales orders linked to mrp.production.
Here is the code what we used. Wondering does someone have better solution?

Inherited mrp.production and added these:

`

def _try_to_get_saleorders(self, origin):
    result = []
    try:
        groups = re.sub('\(.*\)', '', origin)
        groups = groups.replace(" ", "")
        groups = groups.split(',')

        sale_orders = self.env['sale.order'].search([("name", "in", groups)])
        result = sale_orders
    except Exception as e:
        _logger.info('Parsing origin fails %s',e)
    return result

def _compute_sale_order_count(self):
    super()._compute_sale_order_count()
    for production in self:
        if production.sale_order_count == 0:
            production.sale_order_count = len(self._try_to_get_saleorders(production.origin))
      

def action_view_sale_orders(self):
    action = super().action_view_sale_orders()
    if len(self.procurement_group_id.mrp_production_ids.move_dest_ids.group_id.sale_id.ids) == 0:
        sale_order_ids = self._try_to_get_saleorders(self.origin).ids
        if len(sale_order_ids) == 1:
            action.update({
                'view_mode': 'form',
                'res_id': sale_order_ids[0],
            })
        else:
            action.update({
                'name': _("Sources Sale Orders of %s", self.name),
                'domain': [('id', 'in', sale_order_ids)],
                'view_mode': 'tree,form',
            })
    
    return action`
@github-actions
Copy link

There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement stale PR/Issue without recent activity, it'll be soon closed automatically.
Projects
None yet
Development

No branches or pull requests

1 participant