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

14.0 mejoras purchase_portal #50

Merged
merged 6 commits into from
Nov 13, 2024
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
511 changes: 446 additions & 65 deletions purchase_portal/i18n/es.po

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions purchase_portal/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@
from . import product_supplierinfo
from . import res_partner
from . import request_saved_cart
from . import stock_move
59 changes: 49 additions & 10 deletions purchase_portal/models/pms_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,66 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from odoo import fields, models, api, _
from odoo.exceptions import AccessDenied
from odoo import fields, models, api


class PMSProperty(models.Model):
_inherit = 'pms.property'

seller_ids = fields.Many2many('res.partner', string='Vendors allowed in this property')
seller_commercial_ids = fields.Many2many(
'res.partner',
string='Vendors commercial allowed in this property',
relation="pms_property_seller_commercial_rel",
column1="seller_id",
column2="commercial_id",
compute="_compute_seller_commercial_ids",
store=True
)

product_ids = fields.Many2many(
'product.product',
string='Allowed products',
relation="pms_property_product_product_rel",
column1="product_id",
column2="property_id",
)
seller_ids = fields.Many2many('res.partner', string='Vendors allowed in this property')

product_seller_ids = fields.Many2many(
'product.product',
string='Allowed products by seller',
relation="pms_property_product_product_seller_rel",
column1="product_id",
column2="property_id",
)

wharehouse_id = fields.Many2one('stock.warehouse', 'Warehouse')

@api.onchange("seller_ids")
@api.depends('seller_ids')
def _compute_seller_commercial_ids(self):
for record in self:
record.seller_commercial_ids = record.seller_ids.mapped('commercial_partner_id')

@api.onchange("seller_ids", "seller_commercial_ids")
def onchange_seller_ids(self):
if self.seller_ids:
seller_products = self.env['product.supplierinfo'].search([('name', 'in', self.seller_ids.ids)])
seller_product_product = seller_products.mapped('product_tmpl_id.product_variant_ids')
seller_product_product += seller_products.mapped('product_id')
self.product_ids = [(6, 0, seller_product_product.ids)]
for hotel in self:
if hotel.seller_ids:
seller_products = self.env['product.supplierinfo'].search([
'|',
('name', 'in', hotel.seller_ids.ids),
('name', 'in', hotel.seller_commercial_ids.ids)
])
seller_product_product = seller_products.mapped('product_tmpl_id.product_variant_ids')
seller_product_product += seller_products.mapped('product_id')
hotel.product_seller_ids = [(6, 0, seller_product_product.ids)]
else:
hotel.product_seller_ids = [(5,)]

def action_load_all_seller_products(self):
for prop in self:
prop.onchange_seller_ids()
prop.product_ids = prop.product_seller_ids

def action_remove_products_not_in_sellers(self):
for prop in self:
prop.onchange_seller_ids()
prop.product_ids = [(6, 0, prop.product_ids.filtered(lambda x: x.id in prop.product_seller_ids.ids).ids)]
7 changes: 1 addition & 6 deletions purchase_portal/models/pos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
#
##############################################################################

from datetime import datetime
from uuid import uuid4
import pytz

from odoo import api, fields, models, tools, _
from odoo.exceptions import ValidationError, UserError
from odoo import models


class PosConfig(models.Model):
Expand Down
6 changes: 3 additions & 3 deletions purchase_portal/models/pos_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from odoo import fields, models, api, _
from odoo import models, api, _
from odoo.exceptions import AccessDenied


class PosOrder(models.Model):
_inherit = 'pos.order'

@api.model
def _process_order(self, order, draft, existing_order):
order_data = order['data']
pos_session = self.env['pos.session'].browse(order_data['pos_session_id'])
if pos_session.state == 'closing_control' or pos_session.state == 'closed':
raise AccessDenied(_("NO PUEDES CREAR SESIONES DE RESCATE"))
return super()._process_order(order, draft, existing_order)
return super()._process_order(order, draft, existing_order)
11 changes: 3 additions & 8 deletions purchase_portal/models/pos_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################.
###############################################################################

from collections import defaultdict
from datetime import timedelta

from odoo import api, fields, models, _
from odoo.exceptions import AccessError, UserError, ValidationError
from odoo.tools import float_is_zero, float_compare
from odoo import api, models


class PosSession(models.Model):
Expand All @@ -41,4 +36,4 @@ def create(self, values):
'statement_ids': [(6, 0, statement_ids)],
})
res._compute_cash_all()
return res
return res
9 changes: 4 additions & 5 deletions purchase_portal/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from odoo import fields, models, api, _
from odoo.exceptions import AccessDenied
from odoo import fields, models


class ProductProduct(models.Model):
_inherit = 'product.product'

purchase_property_ids = fields.Many2many(
'pms.property',
string='Allowed in properties',
Expand All @@ -40,14 +39,14 @@ def get_supplier_stock(self, purchase_request):
if seller:
supplier_stock = seller.supplier_stock
return supplier_stock

def get_supplier_lowest_price(self):
self.ensure_one()
lowest_price = self.standard_price
if self.seller_ids:
lowest_price = self.seller_ids.sorted(key=lambda r: r.price)[0].price
return lowest_price

def get_first_attachment(self):
self.ensure_one()
return self.env['ir.attachment'].search([('res_model', '=', 'product.template'), ('res_id', '=', self.product_tmpl_id.id)], limit=1)
26 changes: 21 additions & 5 deletions purchase_portal/models/product_supplierinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,36 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from odoo import fields, models, api, _
from odoo.exceptions import AccessDenied
from odoo import fields, models, api


class ProductSupplierinfo(models.Model):
_inherit = 'product.supplierinfo'

supplier_stock = fields.Float('Supplier stock')

@api.model
def create(self, values):
ctx = self.env.context.copy()
res = super(ProductSupplierinfo, self.with_context(ctx).sudo()).create(values)
properties = self.env['pms.property'].search([('seller_ids', 'in', res.name.ids)])
properties = self.env['pms.property'].search([
'|',
('seller_ids', 'in', res.name.ids),
('seller_commercial_ids', 'in', res.name.ids)
])
if properties:
properties.onchange_seller_ids()
return res

@api.model
def unlink(self):
partner_ids = self.mapped('name')
properties = self.env['pms.property'].search([
'|',
('seller_ids', 'in', partner_ids.ids),
('seller_commercial_ids', 'in', partner_ids.ids)
])
res = super(ProductSupplierinfo, self).unlink()
if properties:
properties.onchange_seller_ids()
return res
return res
12 changes: 4 additions & 8 deletions purchase_portal/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@
#
##############################################################################

from datetime import datetime
from uuid import uuid4
import pytz

from odoo import api, fields, models, tools, _
from odoo.exceptions import ValidationError, UserError
from odoo import api, fields, models, _
from odoo.exceptions import UserError


class PurchaseOrder(models.Model):
Expand All @@ -38,9 +34,9 @@ def create(self, values):
if wharehouse_id:
values['picking_type_id'] = self.env['stock.picking.type'].search([('warehouse_id', '=', wharehouse_id), ('code', '=', 'incoming')]).id
return super().create(values)

def button_confirm(self):
force_confirm = self.env.context.get('force_confirm', False)
if not force_confirm and self.partner_id.min_purchase_amount and self.amount_total < self.partner_id.min_purchase_amount:
raise UserError(_('The minimum purchase amount for {} is {}'.format(self.partner_id.name, self.partner_id.min_purchase_amount)))
raise UserError(_('The minimum purchase amount for {} is {}').format(self.partner_id.name, self.partner_id.min_purchase_amount))
return super().button_confirm()
30 changes: 14 additions & 16 deletions purchase_portal/models/purchase_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@

import logging

from datetime import datetime
from uuid import uuid4
import pytz
from lxml import etree
from lxml.html import builder as html

from odoo import api, fields, models, tools, _
from odoo.exceptions import ValidationError, UserError
from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.addons.base.models.ir_mail_server import MailDeliveryException

_logger = logging.getLogger(__name__)


class PurchaseRequest(models.Model):
_name = 'purchase.request'
_inherit = ['purchase.request', 'portal.mixin']
Expand All @@ -49,9 +47,9 @@ def request_validation(self):
res = super(PurchaseRequest, self).request_validation()
if res.reviewer_ids:
base_url = self.env["ir.config_parameter"].sudo().get_param("web.base.url")
text = _("A new <a href='{link}'>review {review}</a> has been asigned to you.".format(
text = _("A new <a href='{link}'>review {review}</a> has been asigned to you.").format(
review=self.display_name, link=base_url + '/web#id=%s&model=purchase.request&view_type=form' % self.id
))
)
message = html.DIV(
html.P(_('Hello,')),
html.P(text)
Expand All @@ -68,11 +66,11 @@ def request_validation(self):
mail_fattura.send(raise_exception=True)
self.message_post(
body=(_("Mail sent for requested review on %s by %s") % (fields.Datetime.now(), self.env.user.display_name))
)
)
except MailDeliveryException as error:
self.message_post(
body=(_("Error when sending mail for requested review: %s") % (error.args[0]))
)
)
return res


Expand All @@ -99,13 +97,13 @@ def create(self, values):
if not min_cost_productinfo:
raise UserError(_('There are no sellers allowed for this request.'))
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 = 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))
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 @@ -116,17 +114,17 @@ def write(self, vals):
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_qty = self.product_id.seller_ids.filtered(lambda x: x.name.id == self.request_id.property_id.seller_id.id).min_qty
# 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:
raise UserError(_('The minimum quantity for this product is %s' % min_qty))
raise UserError(_('The minimum quantity for this product is %s') % min_qty)
if self.request_id.review_ids and not no_msg:
self.request_id.message_post(body=_('Line edited by {user}: <strong>{product} ({old_quantity} -> {quantity})</strong>'.format(user=self.env.user.name, product=self.product_id.name, old_quantity=self.product_qty, quantity=product_qty)))
self.request_id.message_post(body=_('Line edited by {user}: <strong>{product} ({old_quantity} -> {quantity})</strong>').format(user=self.env.user.name, product=self.product_id.name, old_quantity=self.product_qty, quantity=product_qty))
return super().write(vals)

def unlink(self):
if self.request_id.review_ids:
self.request_id.message_post(body=_('Line deleted by {user}: <strong> {product}</strong>'.format(user=self.env.user.name, product=self.product_id.name)))
self.request_id.message_post(body=_('Line deleted by {user}: <strong> {product}</strong>').format(user=self.env.user.name, product=self.product_id.name))
return super().unlink()

def _autocreate_purchase_orders_from_lines(self):
Expand Down
11 changes: 5 additions & 6 deletions purchase_portal/models/request_saved_cart.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# © 2023 Comunitea
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo import fields, models


class WebsiteSavedCart(models.Model):

_name = "purchase.request.saved.cart"
_inherit = "portal.mixin"

name = fields.Char()
partner_id = fields.Many2one(
'res.partner',
Expand All @@ -24,15 +24,15 @@ class WebsiteSavedCart(models.Model):
def _compute_access_url(self):
for cart in self:
cart.access_url = '/my/saved_carts/{}'.format(cart.id)

def _compute_add_to_cart_url(self):
for cart in self:
cart.add_to_cart_url = '/shop/add_saved_cart/{}'.format(cart.id)

def _compute_add_to_cart_and_delete_url(self):
for cart in self:
cart.add_to_cart_and_delete_url = '/shop/add_and_delete_saved_cart/{}'.format(cart.id)

def _compute_delete_url(self):
for cart in self:
cart.delete_url = '/shop/delete_saved_cart/{}'.format(cart.id)
Expand All @@ -41,7 +41,7 @@ def _compute_delete_url(self):
class WebsiteSavedCartItems(models.Model):

_name = "purchase.request.saved.cart.item"

cart_id = fields.Many2one(
'purchase.request.saved.cart',
)
Expand All @@ -56,4 +56,3 @@ class WebsiteSavedCartItems(models.Model):
def _compute_delete_url(self):
for cart in self:
cart.delete_url = '/shop/delete_saved_cart_item/{}'.format(cart.id)

4 changes: 1 addition & 3 deletions purchase_portal/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import uuid
from datetime import date, datetime, timedelta
from odoo import SUPERUSER_ID, _, api, exceptions, models, fields
from odoo import models, fields


class ResPartner(models.Model):
Expand Down
4 changes: 1 addition & 3 deletions purchase_portal/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import uuid
from datetime import date, datetime, timedelta
from odoo import SUPERUSER_ID, _, api, exceptions, models, fields
from odoo import models, fields


class ResUsers(models.Model):
Expand Down
Loading
Loading