From 799fe4cffa2ae8498a92b83930066e6232b97b21 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 1 Apr 2022 11:48:05 +0000 Subject: [PATCH] don en ligne modif js --- __manifest__.py | 3 +- controllers/donation.py | 2 +- models/__init__.py | 1 - models/partner.py | 20 +- models/partner_draft.py | 26 -- security/ir.model.access.csv | 1 - static/src/js/website_sale.js | 828 ++++++++++++++++++++++++++++++++++ views/partner.xml | 10 +- views/partner_draft.xml | 60 --- views/website_donation.xml | 27 +- views/website_sale.xml | 15 +- 11 files changed, 876 insertions(+), 117 deletions(-) create mode 100644 static/src/js/website_sale.js diff --git a/__manifest__.py b/__manifest__.py index 0f6ba74..6d0a92c 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -30,7 +30,6 @@ 'views/email.xml', 'views/phone.xml', 'views/partner.xml', - 'views/partner_draft.xml', 'views/donation.xml', 'views/relationship.xml', 'views/operation.xml', @@ -40,7 +39,7 @@ 'views/payment_batch.xml', 'views/website_sale.xml', 'views/aggregate.xml', - 'wizard/operation_duplicate_wizard.xml', + 'wizard/operation_duplicate_wizard.xml' #'views/website_donation.xml' diff --git a/controllers/donation.py b/controllers/donation.py index f2d5ea9..d626de1 100644 --- a/controllers/donation.py +++ b/controllers/donation.py @@ -4,7 +4,7 @@ from odoo.exceptions import UserError import json -class donation(): +class donation(http.Controller): @http.route(['/makedonation'], type='http', auth="public", methods=['POST'], website=True) def make_donation(self, **kw): diff --git a/models/__init__.py b/models/__init__.py index 3c11525..8c307a7 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -14,4 +14,3 @@ from . import payment_batch from . import sale_order from . import product from . import aggregate -from . import partner_draft \ No newline at end of file diff --git a/models/partner.py b/models/partner.py index 38b4616..aded8fa 100644 --- a/models/partner.py +++ b/models/partner.py @@ -176,8 +176,26 @@ class partner(models.Model): #rec.write({'key':3}) #raise Warning(rec.id) for rec in self.env['res.partner'].search([]): - rec.key=2 + rec.key=int(rec.id)*40456 #raise Warning(len()) + + def _update_source(self): + + #for rec in self.env: + #rec.write({'key':3}) + #raise Warning(rec.id) + for rec in self.env['res.partner'].search([]): + rec.source='joomla' + #raise Warning(len()) + + def _remove_source(self): + + #for rec in self.env: + #rec.write({'key':3}) + #raise Warning(rec.id) + self.env["res.partner"].search([('source','=','joomla')]).unlink() + #raise Warning(len()) + @api.onchange('street') def _onchange_street(self): diff --git a/models/partner_draft.py b/models/partner_draft.py index 69b8d40..ca66b90 100644 --- a/models/partner_draft.py +++ b/models/partner_draft.py @@ -1,32 +1,6 @@ # -*- coding: utf-8 -*- -from odoo import models, fields, api -from odoo.exceptions import UserError, ValidationError -from psycopg2 import sql, DatabaseError -from odoo.tools.safe_eval import safe_eval, datetime -from werkzeug import utils - - - -class opendons_partnerdraft(models.Model): - _name = 'opendons.partnerdraft' - _description = 'import draft partner' - - external_id=fields.Integer(string='external id',required=True) - source=fields.Char(String='source file',required=True) - name=fields.Char(string='name',required=True) - firstname=fields.Char(string='firstname') - phone = fields.Char(string='phone') - mobile = fields.Char(string='mobile') - email = fields.Char(string='email') - complement_ident = fields.Char(string='N° appartment,floor') - complement_geo = fields.Char(string='entry,tower,bat') - street = fields.Char(string='street') - street2 = fields.Char(string='street2') - city = fields.Char(string='city') - zip = fields.Char(string='zip code') - country = fields.Char(string='country') diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv index 2459b75..0ed7ed1 100644 --- a/security/ir.model.access.csv +++ b/security/ir.model.access.csv @@ -24,4 +24,3 @@ access_opendons_payment_batch_qr_code,opendons_payment_batch_qrcode,model_opendo access_opendons_duplicate_operation_wizard,opendons_duplicate_operation_wizard,model_opendons_operation_duplicate,donation.group_donation_manager,1,1,1,1 access_opendons_aggregate_partner,opendons_aggregate_partner,model_opendons_aggregate_partner,donation.group_donation_manager,1,1,1,1 -access_opendons_partnerdraft,opendons_partnerdraft,model_opendons_partnerdraft,donation.group_donation_manager,1,1,1,1 \ No newline at end of file diff --git a/static/src/js/website_sale.js b/static/src/js/website_sale.js new file mode 100644 index 0000000..85c6149 --- /dev/null +++ b/static/src/js/website_sale.js @@ -0,0 +1,828 @@ +odoo.define('website_sale.cart', function (require) { +'use strict'; + +var publicWidget = require('web.public.widget'); +var core = require('web.core'); +var _t = core._t; + +var timeout; + +publicWidget.registry.websiteSaleCartLink = publicWidget.Widget.extend({ + selector: '#top_menu a[href$="/shop/cart"]', + events: { + 'mouseenter': '_onMouseEnter', + 'mouseleave': '_onMouseLeave', + 'click': '_onClick', + }, + + /** + * @constructor + */ + init: function () { + this._super.apply(this, arguments); + this._popoverRPC = null; + }, + /** + * @override + */ + start: function () { + this.$el.popover({ + trigger: 'manual', + animation: true, + html: true, + title: function () { + return _t("My Cart"); + }, + container: 'body', + placement: 'auto', + template: '' + }); + return this._super.apply(this, arguments); + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * @private + * @param {Event} ev + */ + _onMouseEnter: function (ev) { + var self = this; + clearTimeout(timeout); + $(this.selector).not(ev.currentTarget).popover('hide'); + timeout = setTimeout(function () { + if (!self.$el.is(':hover') || $('.mycart-popover:visible').length) { + return; + } + self._popoverRPC = $.get("/shop/cart", { + type: 'popover', + }).then(function (data) { + self.$el.data("bs.popover").config.content = data; + self.$el.popover("show"); + $('.popover').on('mouseleave', function () { + self.$el.trigger('mouseleave'); + }); + }); + }, 300); + }, + /** + * @private + * @param {Event} ev + */ + _onMouseLeave: function (ev) { + var self = this; + setTimeout(function () { + if ($('.popover:hover').length) { + return; + } + if (!self.$el.is(':hover')) { + self.$el.popover('hide'); + } + }, 1000); + }, + /** + * @private + * @param {Event} ev + */ + _onClick: function (ev) { + // When clicking on the cart link, prevent any popover to show up (by + // clearing the related setTimeout) and, if a popover rpc is ongoing, + // wait for it to be completed before going to the link's href. Indeed, + // going to that page may perform the same computation the popover rpc + // is already doing. + clearTimeout(timeout); + if (this._popoverRPC && this._popoverRPC.state() === 'pending') { + ev.preventDefault(); + var href = ev.currentTarget.href; + this._popoverRPC.then(function () { + window.location.href = href; + }); + } + }, +}); +}); + +odoo.define('website_sale.website_sale_category', function (require) { +'use strict'; + +var publicWidget = require('web.public.widget'); + +publicWidget.registry.websiteSaleCategory = publicWidget.Widget.extend({ + selector: '#o_shop_collapse_category', + events: { + 'click .fa-chevron-right': '_onOpenClick', + 'click .fa-chevron-down': '_onCloseClick', + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * @private + * @param {Event} ev + */ + _onOpenClick: function (ev) { + var $fa = $(ev.currentTarget); + $fa.parent().siblings().find('.fa-chevron-down:first').click(); + $fa.parents('li').find('ul:first').show('normal'); + $fa.toggleClass('fa-chevron-down fa-chevron-right'); + }, + /** + * @private + * @param {Event} ev + */ + _onCloseClick: function (ev) { + var $fa = $(ev.currentTarget); + $fa.parent().find('ul:first').hide('normal'); + $fa.toggleClass('fa-chevron-down fa-chevron-right'); + }, +}); +}); + +odoo.define('website_sale.website_sale', function (require) { +'use strict'; + +var core = require('web.core'); +var config = require('web.config'); +var publicWidget = require('web.public.widget'); +var VariantMixin = require('sale.VariantMixin'); +var wSaleUtils = require('website_sale.utils'); +const wUtils = require('website.utils'); +require("web.zoomodoo"); + + +publicWidget.registry.WebsiteSale = publicWidget.Widget.extend(VariantMixin, { + selector: '.oe_website_sale', + events: _.extend({}, VariantMixin.events || {}, { + 'change form .js_product:first input[name="add_qty"]': '_onChangeAddQuantity', + 'mouseup .js_publish': '_onMouseupPublish', + 'touchend .js_publish': '_onMouseupPublish', + 'change .oe_cart input.js_quantity[data-product-id]': '_onChangeCartQuantity', + 'click .oe_cart a.js_add_suggested_products': '_onClickSuggestedProduct', + 'click a.js_add_cart_json': '_onClickAddCartJSON', + 'click .a-submit': '_onClickSubmit', + 'change form.js_attributes input, form.js_attributes select': '_onChangeAttribute', + 'mouseup form.js_add_cart_json label': '_onMouseupAddCartLabel', + 'touchend form.js_add_cart_json label': '_onMouseupAddCartLabel', + 'click .show_coupon': '_onClickShowCoupon', + 'submit .o_wsale_products_searchbar_form': '_onSubmitSaleSearch', + 'change select[name="country_id"]': '_onChangeCountry', + 'change #shipping_use_same': '_onChangeShippingUseSame', + 'click .toggle_summary': '_onToggleSummary', + 'click #add_to_cart, #buy_now, #products_grid .o_wsale_product_btn .a-submit': 'async _onClickAdd', + 'click input.js_product_change': 'onChangeVariant', + 'change .js_main_product [data-attribute_exclusions]': 'onChangeVariant', + 'change oe_optional_products_modal [data-attribute_exclusions]': 'onChangeVariant', + }), + + /** + * @constructor + */ + init: function () { + this._super.apply(this, arguments); + + this._changeCartQuantity = _.debounce(this._changeCartQuantity.bind(this), 500); + this._changeCountry = _.debounce(this._changeCountry.bind(this), 500); + + this.isWebsite = true; + + delete this.events['change .main_product:not(.in_cart) input.js_quantity']; + delete this.events['change [data-attribute_exclusions]']; + }, + /** + * @override + */ + start() { + const def = this._super(...arguments); + + this._applyHashFromSearch(); + + _.each(this.$('div.js_product'), function (product) { + $('input.js_product_change', product).first().trigger('change'); + }); + + // This has to be triggered to compute the "out of stock" feature and the hash variant changes + this.triggerVariantChange(this.$el); + + this.$('select[name="country_id"]').change(); + + core.bus.on('resize', this, function () { + if (config.device.size_class === config.device.SIZES.XL) { + $('.toggle_summary_div').addClass('d-none d-xl-block'); + } + }); + + this._startZoom(); + + window.addEventListener('hashchange', () => { + this._applyHash(); + this.triggerVariantChange(this.$el); + }); + + return def; + }, + /** + * The selector is different when using list view of variants. + * + * @override + */ + getSelectedVariantValues: function ($container) { + var combination = $container.find('input.js_product_change:checked') + .data('combination'); + + if (combination) { + return combination; + } + return VariantMixin.getSelectedVariantValues.apply(this, arguments); + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + _applyHash: function () { + var hash = window.location.hash.substring(1); + if (hash) { + var params = $.deparam(hash); + if (params['attr']) { + var attributeIds = params['attr'].split(','); + var $inputs = this.$('input.js_variant_change, select.js_variant_change option'); + _.each(attributeIds, function (id) { + var $toSelect = $inputs.filter('[data-value_id="' + id + '"]'); + if ($toSelect.is('input[type="radio"]')) { + $toSelect.prop('checked', true); + } else if ($toSelect.is('option')) { + $toSelect.prop('selected', true); + } + }); + this._changeColorAttribute(); + } + } + }, + + /** + * Sets the url hash from the selected product options. + * + * @private + */ + _setUrlHash: function ($parent) { + var $attributes = $parent.find('input.js_variant_change:checked, select.js_variant_change option:selected'); + var attributeIds = _.map($attributes, function (elem) { + return $(elem).data('value_id'); + }); + history.replaceState(undefined, undefined, '#attr=' + attributeIds.join(',')); + }, + /** + * Set the checked color active. + * + * @private + */ + _changeColorAttribute: function () { + $('.css_attribute_color').removeClass("active") + .filter(':has(input:checked)') + .addClass("active"); + }, + /** + * @private + */ + _changeCartQuantity: function ($input, value, $dom_optional, line_id, productIDs) { + _.each($dom_optional, function (elem) { + $(elem).find('.js_quantity').text(value); + productIDs.push($(elem).find('span[data-product-id]').data('product-id')); + }); + $input.data('update_change', true); + + this._rpc({ + route: "/shop/cart/update_json", + params: { + line_id: line_id, + product_id: parseInt($input.data('product-id'), 10), + set_qty: value + }, + }).then(function (data) { + $input.data('update_change', false); + var check_value = parseInt($input.val() || 0, 10); + if (isNaN(check_value)) { + check_value = 1; + } + if (value !== check_value) { + $input.trigger('change'); + return; + } + if (!data.cart_quantity) { + return window.location = '/shop/cart'; + } + wSaleUtils.updateCartNavBar(data); + $input.val(data.quantity); + $('.js_quantity[data-line-id='+line_id+']').val(data.quantity).html(data.quantity); + + if (data.warning) { + var cart_alert = $('.oe_cart').parent().find('#data_warning'); + if (cart_alert.length === 0) { + $('.oe_cart').prepend(''); + } + else { + cart_alert.html(' ' + data.warning); + } + $input.val(data.quantity); + } + }); + }, + /** + * @private + */ + _changeCountry: function () { + if (!$("#country_id").val()) { + return; + } + this._rpc({ + route: "/shop/country_infos/" + $("#country_id").val(), + params: { + mode: $("#country_id").attr('mode'), + }, + }).then(function (data) { + // placeholder phone_code + $("input[name='phone']").attr('placeholder', data.phone_code !== 0 ? '+'+ data.phone_code : ''); + + // populate states and display + var selectStates = $("select[name='state_id']"); + // dont reload state at first loading (done in qweb) + if (selectStates.data('init')===0 || selectStates.find('option').length===1) { + if (data.states.length || data.state_required) { + selectStates.html(''); + _.each(data.states, function (x) { + var opt = $('