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

[ADD] Module to merge draft or confirmed sales orders #341

Merged
merged 4 commits into from
Oct 21, 2016

Conversation

StefanRijnhart
Copy link
Member

No description provided.

@StefanRijnhart StefanRijnhart added this to the 8.0 milestone Sep 28, 2016
@StefanRijnhart StefanRijnhart force-pushed the 8.0-sale_order_merge branch 3 times, most recently from 89c5894 to b5586a4 Compare September 28, 2016 19:17
This module allows the sale employee to merge draft or confirmed orders
from the same customer.

When orders are merged, draft invoices and unprocessed outgoing pickings
Copy link
Member

Choose a reason for hiding this comment

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

Why merging pickings? You can leave them unmerged as Odoo standard allows it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why else merge the orders? This was the main use case of my customer.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, you're right. You can't merge pickings without merging the "upstream" sales orders, or the links will not be totally correct (although the main control is through sales order lines, not through sales orders, but the main information/reports won't be correct).

@JordiBForgeFlow
Copy link
Sponsor Member

I create a SO 1, I confirm and creates a DO1.
I create a SO2 and while in draft, I merge SO2 into SO1.
A DO2 is created, but not merged with DO1.

image

for picking in self.sale_order.picking_ids:
if (picking.state not in ('done', 'cancel') and
picking.location_dest_id.usage == 'customer'):
key = (picking.picking_type_id, picking.location_id,
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Looking towards extensibility, please build the key in a separate method. We work, for instance, on another model that various pickings for a sales order, based on the requested date maintained at sales order line level. In this case, when we merge orders we'd want to respect the scheduled date.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

('partner_shipping_id', '=', sale.partner_shipping_id.id),
('warehouse_id', '=', sale.warehouse_id.id),
('state', 'in', self.MERGE_STATES),
] + policy_clause
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Looking towards extensibility, please build the domain in a separate method. For example, in sale_operating_unit (OCA/operating-unit#22) you would not want to merge sales orders that belong to separate operating units. Also, why is the company_id not included?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

target = pickings[0]
pickings -= target
pickings.move_lines.write({'picking_id': target.id})
pickings.unlink()
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

In the context of real time inventory valuation this will cause that the journal entries created from the partial transfers of pickings will refer to a deleted picking (https://github.com/odoo/odoo/blob/8.0/addons/stock_account/stock_account.py#L278)
Perhaps it would be a good idea to add here a hook (at least) that would allow to update these journal entries.

Copy link
Member Author

Choose a reason for hiding this comment

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

Only draft pickings are merged and deleted, so this is not an issue right?

@StefanRijnhart
Copy link
Member Author

@jbeficent cannot seem to reply directly to #341 (comment), but I cannot reproduce this. What are the order settings of SO1 and SO2?

@StefanRijnhart
Copy link
Member Author

@jbeficent found them on the runbot

@StefanRijnhart
Copy link
Member Author

@jbeficent You got multiple DO's for the merged order because the runbot instance has the module 'sale procurement group per line' installed. I uninstalled it and it works now.

[FIX] Add company to merge domain
[FIX] Fix syntax error in case multiple pickings are merged
pickings -= target
pickings.mapped('move_lines').write({'picking_id': target.id})
pickings.unlink()
return True
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

The final picking should have as Source Document the final sales order, not the original.

image

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Remove the orders that you do not want to merge, and click on the *Merge*
button in the footer of the pop-up window. The main window will then refresh
to the updated main sale order.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

I suggest to add the following:

The mergeability criteria is defined as follows:

  • Same customer, shipping address, warehouse and company.
  • Orders in status 'Draft Quotation', 'Quotation Sent', 'Waiting Shedule', 'Sale Order', 'Sale to Invoice'.
  • Once the order has already been confirmed, only draft orders or confirmed orders with the same invoice policy can be merged.

The criteria can easily be extended using method _get_merge_domain of model sale.order

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Thanks for the review BTW.

[UPD] README, courtesy of Jordi Ballester
@StefanRijnhart
Copy link
Member Author

Hi @jbeficient, would you like to revise your review based on my changes?

@JordiBForgeFlow
Copy link
Sponsor Member

@StefanRijnhart This has all the required approvals. Can I merge now?

@StefanRijnhart
Copy link
Member Author

As it has the two require approvals, yes!

@pedrobaeza
Copy link
Member

Remember to squash on merge as this case there is no significant different commits

@JordiBForgeFlow JordiBForgeFlow merged commit b780259 into OCA:8.0 Oct 21, 2016
@StefanRijnhart
Copy link
Member Author

Thanks ;-)

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

Successfully merging this pull request may close these issues.

None yet

4 participants