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

Usar el hijo como proveedor si no está en el hotel para las compras #55

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions purchase_portal/controllers/prequest_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################

import json
from odoo import http
from odoo import http, _
from odoo.http import request
from odoo.tools.misc import get_lang

Expand Down Expand Up @@ -78,7 +78,11 @@ def get_purchase_request_product_table(self, **kw):
product_ids = product_ids.filtered(lambda x: x.categ_id.id == int(category_id))

if seller_id and seller_id != 'all':
product_ids = product_ids.filtered(lambda x: int(seller_id) in x.seller_ids.mapped('name').ids)
partner_id = request.env['res.partner'].browse(int(seller_id))
product_ids = product_ids.filtered(
lambda x: partner_id.id in x.seller_ids.mapped('name').ids
or partner_id.commercial_partner_id.id in x.seller_ids.mapped('name').ids
)

if request.env.user.banned_product_ids:
product_ids = product_ids - request.env.user.banned_product_ids
Expand Down Expand Up @@ -109,7 +113,7 @@ def purchase_request_add_product(self, **kw):
return json.dumps(
{
"error": True,
"message": "Missing parameters",
"message": _("Missing parameters"),
}
)

Expand All @@ -118,13 +122,18 @@ def purchase_request_add_product(self, **kw):
return json.dumps(
{
"error": True,
"message": "No purchase_request or wrong state",
"message": _("No purchase_request or wrong state"),
}
)
try:
product_info = request.env['product.supplierinfo'].search([
('name', 'in', purchase_request.property_id.seller_ids.ids), '|', ('product_id', '=', int(product_id)), ('product_tmpl_id.product_variant_ids', '=', int(product_id))], order='price asc', limit=1
)
'|',
('name', 'in', purchase_request.property_id.seller_ids.ids),
('name', 'in', purchase_request.property_id.seller_commercial_ids.ids),
'|',
('product_id', '=', int(product_id)),
('product_tmpl_id.product_variant_ids', '=', int(product_id))
], order='price asc', limit=1)
request_line = request.env['purchase.request.line'].with_context(portal=True).create({
'request_id': purchase_request.id,
'product_id': int(product_id),
Expand Down
16 changes: 14 additions & 2 deletions purchase_portal/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-17 17:27+0000\n"
"PO-Revision-Date: 2024-12-17 17:27+0000\n"
"POT-Creation-Date: 2024-12-19 12:41+0000\n"
"PO-Revision-Date: 2024-12-19 12:41+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -1023,6 +1023,12 @@ msgstr "Contenido mail a proveedor"
msgid "Minimum purchase amount"
msgstr "Importe mínimo de compra"

#. module: purchase_portal
#: code:addons/purchase_portal/controllers/prequest_json.py:0
#, python-format
msgid "Missing parameters"
msgstr "Faltan parámetros"

#. module: purchase_portal
#: model:ir.model.fields,field_description:purchase_portal.field_purchase_request_line_make_purchase_order__multiple_suppliers
msgid "Multiple suppliers"
Expand Down Expand Up @@ -1055,6 +1061,12 @@ msgstr "Nueva línea añadida por {user}: <strong> {product} ({quantity})</stron
msgid "New purchase request"
msgstr "Nueva solicitud de compra"

#. module: purchase_portal
#: code:addons/purchase_portal/controllers/prequest_json.py:0
#, python-format
msgid "No purchase_request or wrong state"
msgstr "No hay solicitud de compra o estado incorrecto"

#. module: purchase_portal
#: model_terms:ir.ui.view,arch_db:purchase_portal.portal_my_saved_carts
#: model_terms:ir.ui.view,arch_db:purchase_portal.portal_saved_cart_page
Expand Down
1 change: 0 additions & 1 deletion purchase_portal/models/product_supplierinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class ProductSupplierinfo(models.Model):
'res.partner',
string='Seller children',
compute='_compute_seller_children_ids',
store=True,
readonly=True
)

Expand Down
34 changes: 29 additions & 5 deletions purchase_portal/models/purchase_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,30 @@ def create(self, values):
product = self.env['product.product'].browse(product_id)
if not product.seller_ids:
raise UserError(_('There are no sellers for this product in the current company.'))
min_cost_productinfo = product.seller_ids.filtered(lambda x: x.name.id in request.property_id.seller_ids.ids).sorted(key=lambda r: r.price)[0]
min_cost_productinfo = product.seller_ids.filtered(
lambda x: x.name.id in request.property_id.seller_ids.ids
or x.name.id in request.property_id.seller_commercial_ids.ids
).sorted(key=lambda r: r.price)[0]
if not min_cost_productinfo:
raise UserError(_('There are no sellers allowed for this request.'))
values['suggested_supplier_id'] = min_cost_productinfo.name.id
if min_cost_productinfo.name not in request.property_id.seller_ids:
values['supplier_id'] = request.property_id.seller_ids.filtered(
lambda x: x.commercial_partner_id.id == min_cost_productinfo.name.id
).id
values['suggested_supplier_id'] = request.property_id.seller_ids.filtered(
lambda x: x.commercial_partner_id.id == min_cost_productinfo.name.id
).id
else:
values['suggested_supplier_id'] = min_cost_productinfo.name.id
# min_qty = product.seller_ids.filtered(lambda x: x.name.id == request.property_id.seller_id.id).min_qty
min_qty = min_cost_productinfo.min_qty

if product_qty < min_qty:
raise UserError(_('The minimum quantity for this product is %s') % min_qty)
if request.review_ids:
request.message_post(body=_('New line added by {user}: <strong> {product} ({quantity})</strong>').format(user=self.env.user.name, product=product.name, quantity=product_qty))
request.message_post(body=_(
'New line added by {user}: <strong> {product} ({quantity})</strong>'
).format(user=self.env.user.name, product=product.name, quantity=product_qty))
return super().create(values)

def write(self, vals):
Expand All @@ -112,8 +125,19 @@ def write(self, vals):
product_qty = vals.get('product_qty', False)
no_msg = ctx.get('no_msg', False)
if portal and product_qty:
min_cost_productinfo = self.product_id.seller_ids.filtered(lambda x: x.name.id in self.request_id.property_id.seller_ids.ids).sorted(key=lambda r: r.price)[0]
vals['suggested_supplier_id'] = min_cost_productinfo.name.id
min_cost_productinfo = self.product_id.seller_ids.filtered(
lambda x: x.name.id in self.request_id.property_id.seller_ids.ids
or x.name.id in self.request_id.property_id.seller_commercial_ids.ids
).sorted(key=lambda r: r.price)[0]
if min_cost_productinfo.name not in self.request_id.property_id.seller_ids:
vals['supplier_id'] = self.request_id.property_id.seller_ids.filtered(
lambda x: x.commercial_partner_id.id == min_cost_productinfo.name.id
).id
vals['suggested_supplier_id'] = self.request_id.property_id.seller_ids.filtered(
lambda x: x.commercial_partner_id.id == min_cost_productinfo.name.id
).id
else:
vals['suggested_supplier_id'] = min_cost_productinfo.name.id
# min_qty = self.product_id.seller_ids.filtered(lambda x: x.name.id == self.request_id.property_id.seller_id.id).min_qty
min_qty = min_cost_productinfo.min_qty
if product_qty < min_qty:
Expand Down
30 changes: 20 additions & 10 deletions purchase_portal/templates/purchase_request.xml
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
</select>
<select name="product_seller" class="purchase_seller ml-2" t-att-data-purchase_request="purchase_request.id" t-att-data-property_id="current_property_id.id">
<option value="all">All sellers</option>
<t t-foreach="current_property_id.product_ids.mapped('seller_ids').mapped('name')" t-as="seller">
<t t-foreach="current_property_id.product_ids.seller_ids.filtered(lambda x: x.name in purchase_request.property_id.seller_ids).mapped('name')" t-as="seller">
<option t-att-value="seller.id">
<t t-esc="seller.name"/>
</option>
Expand Down Expand Up @@ -321,15 +321,25 @@
<span t-field="product.uom_po_id"/>
</td>
<td class="text-right">
<t t-if="product.mapped('seller_ids').mapped('name') and purchase_request.property_id.seller_ids">
<t t-foreach="product.mapped('seller_ids').filtered(lambda x: x.name in (purchase_request.property_id.seller_ids + purchase_request.property_id.seller_commercial_ids)).mapped('name')" t-as="seller">
<span class="ml-2">
<t t-esc="seller.display_name"/><br/>
<t t-esc="seller.email"/><br/>
<t t-esc="seller.phone"/>
</span>
<br t-if="seller.id != product.mapped('seller_ids').mapped('name')[-1].id" />
<hr t-if="seller.id != product.mapped('seller_ids').mapped('name')[-1].id" />
<t t-if="product.mapped('seller_ids.name') and purchase_request.property_id.seller_ids">
<t t-foreach="product.seller_ids.filtered(lambda x: x.name in (purchase_request.property_id.seller_ids + purchase_request.property_id.seller_commercial_ids)).mapped('name')" t-as="seller">
<t t-if="seller not in purchase_request.property_id.seller_ids">
<t t-set="seller_child" t-value="purchase_request.property_id.seller_ids.filtered(lambda x: x.commercial_partner_id == seller)"/>
<span class="ml-2">
<t t-esc="seller_child.name"/><br/>
<t t-esc="seller_child.email"/><br/>
<t t-esc="seller_child.phone"/>
</span>
</t>
<t t-else="">
<span class="ml-2">
<t t-esc="seller.name"/><br/>
<t t-esc="seller.email"/><br/>
<t t-esc="seller.phone"/>
</span>
</t>
<br t-if="seller.id != product.mapped('seller_ids.name')[-1].id" />
<hr t-if="seller.id != product.mapped('seller_ids.name')[-1].id" />
</t>
</t>
</td>
Expand Down
Loading