Files
odoo_source/addons/purchase_requisition/wizard/purchase_requisition_create_alternative.py
T
MerlinGuillaume 86959e5865 [FIX] purchase_requisition_stock: alternative's RFQ delivery address
When generating an alternative request for quotation from a dropship
purchase, the delivery address is not copied

Steps to reproduce:
1. Install Sales and stock_dropshipping module
2. Go to Settings > General Settings > Users > Manage Users, open user
Mitchell Admin and in the Access Rights tab enable 'Manage Multiple
Stock Locations'
3. Go to Settings > Sales > Quotations & Orders and enable Customer
Addresses
4. Go to Settings > Purchase > Orders and enable Purchase Agreements
5. Go to Sales > Products > Products and edit a product (e.g. 'Acoustic
Bloc Screens')
- In the Inventory tab enable routes 'Buy' and 'Dropship'
6. Create a Sale Order for this product with a different Delivery
Address then the Customer and confirm it
7. Go to the purchase order
8. In the Alternatives tab create an alternative
9. The Dropship Address is not repercuted on the new RFQ

Solution:
Add a method `_get_alternative_values` which sets the dest_address_id
and is extended in `purchase_requisition_stock` to add the
picking_type_id

opw-2880042

closes odoo/odoo#94109

X-original-commit: a7ef5d93650c262497d3a02b934284829cfc5021
Signed-off-by: Adrien Widart <awt@odoo.com>
Signed-off-by: Guillaume Merlin (megu) <megu@odoo.com>
2022-06-29 12:19:15 +02:00

83 lines
4.1 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import _, api, fields, models, Command
from odoo.exceptions import UserError
class PurchaseRequisitionCreateAlternative(models.TransientModel):
_name = 'purchase.requisition.create.alternative'
_description = 'Wizard to preset values for alternative PO'
origin_po_id = fields.Many2one(
'purchase.order', help="The original PO that this alternative PO is being created for."
)
partner_id = fields.Many2one(
'res.partner', string='Vendor', required=True,
help="Choose a vendor for alternative PO")
creation_blocked = fields.Boolean(
help="If the chosen vendor or if any of the products in the original PO have a blocking warning then we prevent creation of alternative PO. "
"This is because normally these fields are cleared w/warning message within form view, but we cannot recreate that in this case.",
compute="_compute_purchase_warn",
groups="purchase.group_warning_purchase")
purchase_warn_msg = fields.Text(
'Warning Messages',
compute="_compute_purchase_warn",
groups="purchase.group_warning_purchase")
copy_products = fields.Boolean(
"Copy Products", default=True,
help="If this is checked, the product quantites of the original PO will be copied")
@api.depends('partner_id', 'copy_products')
def _compute_purchase_warn(self):
self.creation_blocked = False
self.purchase_warn_msg = ''
# follows partner warning logic from PurchaseOrder
if not self.env.user.has_group('purchase.group_warning_purchase'):
return
partner = self.partner_id
# If partner has no warning, check its company
if partner and partner.purchase_warn == 'no-message':
partner = partner.parent_id
if partner and partner.purchase_warn != 'no-message':
self.purchase_warn_msg = _("Warning for %(partner)s:\n%(warning_message)s\n", partner=partner.name, warning_message=partner.purchase_warn_msg)
if partner.purchase_warn == 'block':
self.creation_blocked = True
self.purchase_warn_msg += _("This is a blocking warning!\n")
if self.copy_products and self.origin_po_id.order_line:
for line in self.origin_po_id.order_line:
if line.product_id.purchase_line_warn != 'no-message':
self.purchase_warn_msg += _("Warning for %(product)s:\n%(warning_message)s\n", product=line.product_id.name, warning_message=line.product_id.purchase_line_warn_msg)
if line.product_id.purchase_line_warn == 'block':
self.creation_blocked = True
self.purchase_warn_msg += _("This is a blocking warning!\n")
def action_create_alternative(self):
if self.env.user.has_group('purchase.group_warning_purchase') and self.creation_blocked:
raise UserError(
_('The vendor you have selected or at least one of the products you are copying from the original '
'order has a blocking warning on it and cannot be selected to create an alternative.')
)
vals = self._get_alternative_values()
alt_po = self.env['purchase.order'].with_context(origin_po_id=self.origin_po_id.id).create(vals)
return {
'type': 'ir.actions.act_window',
'view_mode': 'form',
'res_model': 'purchase.order',
'res_id': alt_po.id,
'context': {
'active_id': alt_po.id,
},
}
def _get_alternative_values(self):
vals = {
'date_order': self.origin_po_id.date_order,
'partner_id': self.partner_id.id,
'user_id': self.origin_po_id.user_id.id,
'dest_address_id': self.origin_po_id.dest_address_id.id,
}
if self.copy_products and self.origin_po_id:
vals['order_line'] = [Command.create({'product_id': line.product_id.id, 'product_qty': line.product_qty}) for line in self.origin_po_id.order_line]
return vals