From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/product/static/description/icon.png | Bin 0 -> 5400 bytes addons/product/static/description/icon.svg | 1 + addons/product/static/img/membership_0-image.jpg | Bin 0 -> 3796 bytes addons/product/static/img/membership_1-image.jpg | Bin 0 -> 3158 bytes addons/product/static/img/membership_2-image.jpg | Bin 0 -> 3691 bytes addons/product/static/img/product_chair.png | Bin 0 -> 32050 bytes addons/product/static/img/product_lamp.png | Bin 0 -> 14167 bytes .../product/static/img/product_product_1-image.jpg | Bin 0 -> 3969 bytes .../static/img/product_product_10-image.png | Bin 0 -> 20655 bytes .../static/img/product_product_11-image.png | Bin 0 -> 24286 bytes .../static/img/product_product_12-image.png | Bin 0 -> 28317 bytes .../static/img/product_product_13-image.png | Bin 0 -> 12454 bytes .../static/img/product_product_16-image.png | Bin 0 -> 77362 bytes .../static/img/product_product_20-image.png | Bin 0 -> 23325 bytes .../static/img/product_product_22-image.png | Bin 0 -> 17593 bytes .../static/img/product_product_24-image.png | Bin 0 -> 35809 bytes .../static/img/product_product_25-image.png | Bin 0 -> 49141 bytes .../static/img/product_product_27-image.png | Bin 0 -> 22309 bytes .../product/static/img/product_product_3-image.jpg | Bin 0 -> 2947 bytes .../static/img/product_product_43-image.jpg | Bin 0 -> 10796 bytes .../static/img/product_product_46-image.png | Bin 0 -> 34606 bytes .../product/static/img/product_product_5-image.png | Bin 0 -> 16584 bytes .../product/static/img/product_product_6-image.png | Bin 0 -> 22715 bytes .../product/static/img/product_product_7-image.png | Bin 0 -> 50657 bytes .../product/static/img/product_product_8-image.png | Bin 0 -> 17943 bytes .../product/static/img/product_product_9-image.png | Bin 0 -> 34588 bytes .../static/img/product_product_d01-image.png | Bin 0 -> 30015 bytes .../static/img/product_product_d03-image.png | Bin 0 -> 42437 bytes addons/product/static/img/table01.png | Bin 0 -> 18385 bytes addons/product/static/img/table02.png | Bin 0 -> 14067 bytes addons/product/static/img/table03.png | Bin 0 -> 15542 bytes addons/product/static/img/table04.png | Bin 0 -> 21610 bytes .../static/src/js/product_pricelist_report.js | 291 +++++++++++++++++++++ addons/product/static/src/xml/pricelist_report.xml | 51 ++++ .../static/tests/product_pricelist_report_test.js | 146 +++++++++++ addons/product/static/xls/product_pricelist.xls | Bin 0 -> 32768 bytes addons/product/static/xls/product_supplierinfo.xls | Bin 0 -> 31744 bytes addons/product/static/xls/product_template.xls | Bin 0 -> 36352 bytes 38 files changed, 489 insertions(+) create mode 100644 addons/product/static/description/icon.png create mode 100644 addons/product/static/description/icon.svg create mode 100644 addons/product/static/img/membership_0-image.jpg create mode 100644 addons/product/static/img/membership_1-image.jpg create mode 100644 addons/product/static/img/membership_2-image.jpg create mode 100644 addons/product/static/img/product_chair.png create mode 100644 addons/product/static/img/product_lamp.png create mode 100644 addons/product/static/img/product_product_1-image.jpg create mode 100644 addons/product/static/img/product_product_10-image.png create mode 100644 addons/product/static/img/product_product_11-image.png create mode 100644 addons/product/static/img/product_product_12-image.png create mode 100644 addons/product/static/img/product_product_13-image.png create mode 100644 addons/product/static/img/product_product_16-image.png create mode 100644 addons/product/static/img/product_product_20-image.png create mode 100644 addons/product/static/img/product_product_22-image.png create mode 100644 addons/product/static/img/product_product_24-image.png create mode 100644 addons/product/static/img/product_product_25-image.png create mode 100644 addons/product/static/img/product_product_27-image.png create mode 100644 addons/product/static/img/product_product_3-image.jpg create mode 100644 addons/product/static/img/product_product_43-image.jpg create mode 100644 addons/product/static/img/product_product_46-image.png create mode 100644 addons/product/static/img/product_product_5-image.png create mode 100644 addons/product/static/img/product_product_6-image.png create mode 100644 addons/product/static/img/product_product_7-image.png create mode 100644 addons/product/static/img/product_product_8-image.png create mode 100644 addons/product/static/img/product_product_9-image.png create mode 100644 addons/product/static/img/product_product_d01-image.png create mode 100644 addons/product/static/img/product_product_d03-image.png create mode 100644 addons/product/static/img/table01.png create mode 100644 addons/product/static/img/table02.png create mode 100644 addons/product/static/img/table03.png create mode 100644 addons/product/static/img/table04.png create mode 100644 addons/product/static/src/js/product_pricelist_report.js create mode 100644 addons/product/static/src/xml/pricelist_report.xml create mode 100644 addons/product/static/tests/product_pricelist_report_test.js create mode 100644 addons/product/static/xls/product_pricelist.xls create mode 100644 addons/product/static/xls/product_supplierinfo.xls create mode 100644 addons/product/static/xls/product_template.xls (limited to 'addons/product/static') diff --git a/addons/product/static/description/icon.png b/addons/product/static/description/icon.png new file mode 100644 index 00000000..2079879b Binary files /dev/null and b/addons/product/static/description/icon.png differ diff --git a/addons/product/static/description/icon.svg b/addons/product/static/description/icon.svg new file mode 100644 index 00000000..2b0b6824 --- /dev/null +++ b/addons/product/static/description/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/addons/product/static/img/membership_0-image.jpg b/addons/product/static/img/membership_0-image.jpg new file mode 100644 index 00000000..f9723384 Binary files /dev/null and b/addons/product/static/img/membership_0-image.jpg differ diff --git a/addons/product/static/img/membership_1-image.jpg b/addons/product/static/img/membership_1-image.jpg new file mode 100644 index 00000000..ade87446 Binary files /dev/null and b/addons/product/static/img/membership_1-image.jpg differ diff --git a/addons/product/static/img/membership_2-image.jpg b/addons/product/static/img/membership_2-image.jpg new file mode 100644 index 00000000..ed6f4118 Binary files /dev/null and b/addons/product/static/img/membership_2-image.jpg differ diff --git a/addons/product/static/img/product_chair.png b/addons/product/static/img/product_chair.png new file mode 100644 index 00000000..5add5e91 Binary files /dev/null and b/addons/product/static/img/product_chair.png differ diff --git a/addons/product/static/img/product_lamp.png b/addons/product/static/img/product_lamp.png new file mode 100644 index 00000000..03e6bb60 Binary files /dev/null and b/addons/product/static/img/product_lamp.png differ diff --git a/addons/product/static/img/product_product_1-image.jpg b/addons/product/static/img/product_product_1-image.jpg new file mode 100644 index 00000000..7fc47569 Binary files /dev/null and b/addons/product/static/img/product_product_1-image.jpg differ diff --git a/addons/product/static/img/product_product_10-image.png b/addons/product/static/img/product_product_10-image.png new file mode 100644 index 00000000..a839c7fe Binary files /dev/null and b/addons/product/static/img/product_product_10-image.png differ diff --git a/addons/product/static/img/product_product_11-image.png b/addons/product/static/img/product_product_11-image.png new file mode 100644 index 00000000..156e5ebd Binary files /dev/null and b/addons/product/static/img/product_product_11-image.png differ diff --git a/addons/product/static/img/product_product_12-image.png b/addons/product/static/img/product_product_12-image.png new file mode 100644 index 00000000..d606721f Binary files /dev/null and b/addons/product/static/img/product_product_12-image.png differ diff --git a/addons/product/static/img/product_product_13-image.png b/addons/product/static/img/product_product_13-image.png new file mode 100644 index 00000000..96baa3d9 Binary files /dev/null and b/addons/product/static/img/product_product_13-image.png differ diff --git a/addons/product/static/img/product_product_16-image.png b/addons/product/static/img/product_product_16-image.png new file mode 100644 index 00000000..dfbb75c9 Binary files /dev/null and b/addons/product/static/img/product_product_16-image.png differ diff --git a/addons/product/static/img/product_product_20-image.png b/addons/product/static/img/product_product_20-image.png new file mode 100644 index 00000000..59f670fe Binary files /dev/null and b/addons/product/static/img/product_product_20-image.png differ diff --git a/addons/product/static/img/product_product_22-image.png b/addons/product/static/img/product_product_22-image.png new file mode 100644 index 00000000..aa581b69 Binary files /dev/null and b/addons/product/static/img/product_product_22-image.png differ diff --git a/addons/product/static/img/product_product_24-image.png b/addons/product/static/img/product_product_24-image.png new file mode 100644 index 00000000..f6a8ded9 Binary files /dev/null and b/addons/product/static/img/product_product_24-image.png differ diff --git a/addons/product/static/img/product_product_25-image.png b/addons/product/static/img/product_product_25-image.png new file mode 100644 index 00000000..947aa549 Binary files /dev/null and b/addons/product/static/img/product_product_25-image.png differ diff --git a/addons/product/static/img/product_product_27-image.png b/addons/product/static/img/product_product_27-image.png new file mode 100644 index 00000000..8c54433b Binary files /dev/null and b/addons/product/static/img/product_product_27-image.png differ diff --git a/addons/product/static/img/product_product_3-image.jpg b/addons/product/static/img/product_product_3-image.jpg new file mode 100644 index 00000000..33884c0b Binary files /dev/null and b/addons/product/static/img/product_product_3-image.jpg differ diff --git a/addons/product/static/img/product_product_43-image.jpg b/addons/product/static/img/product_product_43-image.jpg new file mode 100644 index 00000000..3bab8a3f Binary files /dev/null and b/addons/product/static/img/product_product_43-image.jpg differ diff --git a/addons/product/static/img/product_product_46-image.png b/addons/product/static/img/product_product_46-image.png new file mode 100644 index 00000000..d9525984 Binary files /dev/null and b/addons/product/static/img/product_product_46-image.png differ diff --git a/addons/product/static/img/product_product_5-image.png b/addons/product/static/img/product_product_5-image.png new file mode 100644 index 00000000..53d161e2 Binary files /dev/null and b/addons/product/static/img/product_product_5-image.png differ diff --git a/addons/product/static/img/product_product_6-image.png b/addons/product/static/img/product_product_6-image.png new file mode 100644 index 00000000..a6c0299f Binary files /dev/null and b/addons/product/static/img/product_product_6-image.png differ diff --git a/addons/product/static/img/product_product_7-image.png b/addons/product/static/img/product_product_7-image.png new file mode 100644 index 00000000..7ee0a189 Binary files /dev/null and b/addons/product/static/img/product_product_7-image.png differ diff --git a/addons/product/static/img/product_product_8-image.png b/addons/product/static/img/product_product_8-image.png new file mode 100644 index 00000000..acc3afcd Binary files /dev/null and b/addons/product/static/img/product_product_8-image.png differ diff --git a/addons/product/static/img/product_product_9-image.png b/addons/product/static/img/product_product_9-image.png new file mode 100644 index 00000000..580f1c3c Binary files /dev/null and b/addons/product/static/img/product_product_9-image.png differ diff --git a/addons/product/static/img/product_product_d01-image.png b/addons/product/static/img/product_product_d01-image.png new file mode 100644 index 00000000..28e1a8d5 Binary files /dev/null and b/addons/product/static/img/product_product_d01-image.png differ diff --git a/addons/product/static/img/product_product_d03-image.png b/addons/product/static/img/product_product_d03-image.png new file mode 100644 index 00000000..854660b5 Binary files /dev/null and b/addons/product/static/img/product_product_d03-image.png differ diff --git a/addons/product/static/img/table01.png b/addons/product/static/img/table01.png new file mode 100644 index 00000000..9aa8ef1d Binary files /dev/null and b/addons/product/static/img/table01.png differ diff --git a/addons/product/static/img/table02.png b/addons/product/static/img/table02.png new file mode 100644 index 00000000..5291a47f Binary files /dev/null and b/addons/product/static/img/table02.png differ diff --git a/addons/product/static/img/table03.png b/addons/product/static/img/table03.png new file mode 100644 index 00000000..9da4c637 Binary files /dev/null and b/addons/product/static/img/table03.png differ diff --git a/addons/product/static/img/table04.png b/addons/product/static/img/table04.png new file mode 100644 index 00000000..28fdd46b Binary files /dev/null and b/addons/product/static/img/table04.png differ diff --git a/addons/product/static/src/js/product_pricelist_report.js b/addons/product/static/src/js/product_pricelist_report.js new file mode 100644 index 00000000..c040a190 --- /dev/null +++ b/addons/product/static/src/js/product_pricelist_report.js @@ -0,0 +1,291 @@ +odoo.define('product.generate_pricelist', function (require) { +'use strict'; + +var AbstractAction = require('web.AbstractAction'); +var core = require('web.core'); +var FieldMany2One = require('web.relational_fields').FieldMany2One; +var StandaloneFieldManagerMixin = require('web.StandaloneFieldManagerMixin'); +var Widget = require('web.Widget'); + +var QWeb = core.qweb; +var _t = core._t; + +var QtyTagWidget = Widget.extend({ + template: 'product.report_pricelist_qty', + events: { + 'click .o_remove_qty': '_onClickRemoveQty', + }, + /** + * @override + */ + init: function (parent, defaulQuantities) { + this._super.apply(this, arguments); + this.quantities = defaulQuantities; + this.MAX_QTY = 5; + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Add a quantity when add(+) button clicked. + * + * @private + */ + _onClickAddQty: function () { + if (this.quantities.length >= this.MAX_QTY) { + this.do_notify(false, _.str.sprintf( + _t("At most %d quantities can be displayed simultaneously. Remove a selected quantity to add others."), + this.MAX_QTY + )); + return; + } + const qty = parseInt(this.$('.o_product_qty').val()); + if (qty && qty > 0) { + // Check qty already exist + if (this.quantities.indexOf(qty) === -1) { + this.quantities.push(qty); + this.quantities = this.quantities.sort((a, b) => a - b); + this.trigger_up('qty_changed', {quantities: this.quantities}); + this.renderElement(); + } else { + this.displayNotification({ + message: _.str.sprintf(_t("Quantity already present (%d)."), qty), + type: 'info' + }); + } + } else { + this.do_notify(false, _t("Please enter a positive whole number")); + } + }, + /** + * Remove quantity. + * + * @private + * @param {jQueryEvent} ev + */ + _onClickRemoveQty: function (ev) { + const qty = parseInt($(ev.currentTarget).closest('.badge').data('qty')); + this.quantities = this.quantities.filter(q => q !== qty); + this.trigger_up('qty_changed', {quantities: this.quantities}); + this.renderElement(); + }, +}); + +var GeneratePriceList = AbstractAction.extend(StandaloneFieldManagerMixin, { + hasControlPanel: true, + events: { + 'click .o_action': '_onClickAction', + 'submit form': '_onSubmitForm', + }, + custom_events: Object.assign({}, StandaloneFieldManagerMixin.custom_events, { + field_changed: '_onFieldChanged', + qty_changed: '_onQtyChanged', + }), + /** + * @override + */ + init: function (parent, params) { + this._super.apply(this, arguments); + StandaloneFieldManagerMixin.init.call(this); + this.context = params.context; + // in case the window got refreshed + if (params.params && params.params.active_ids && typeof(params.params.active_ids === 'string')) { + try { + this.context.active_ids = params.params.active_ids.split(',').map(id => parseInt(id)); + this.context.active_model = params.params.active_model; + } catch(e) { + console.log('unable to load ids from the url fragment 🙁'); + } + } + if (!this.context.active_model) { + // started without an active module, assume product templates + this.context.active_model = 'product.template'; + } + this.context.quantities = [1, 5, 10]; + }, + /** + * @override + */ + willStart: function () { + let getPricelit; + // started without a selected pricelist in context? just get the first one + if (this.context.default_pricelist) { + getPricelit = Promise.resolve([this.context.default_pricelist]); + } else { + getPricelit = this._rpc({ + model: 'product.pricelist', + method: 'search', + args: [[]], + kwargs: {limit: 1} + }) + } + const fieldSetup = getPricelit.then(pricelistIds => { + return this.model.makeRecord('report.product.report_pricelist', [{ + name: 'pricelist_id', + type: 'many2one', + relation: 'product.pricelist', + value: pricelistIds[0], + }]); + }).then(recordID => { + const record = this.model.get(recordID); + this.many2one = new FieldMany2One(this, 'pricelist_id', record, { + mode: 'edit', + attrs: { + can_create: false, + can_write: false, + options: {no_open: true}, + }, + }); + this._registerWidget(recordID, 'pricelist_id', this.many2one); + }); + return Promise.all([fieldSetup, this._getHtml(), this._super()]); + }, + /** + * @override + */ + start: function () { + this.controlPanelProps.cp_content = this._renderComponent(); + return this._super.apply(this, arguments).then(() => { + this.$('.o_content').html(this.reportHtml); + }); + }, + /** + * Include the current model (template/variant) in the state to allow refreshing without losing + * the proper context. + * @override + */ + getState: function() { + return { + active_model: this.context.active_model, + }; + }, + getTitle: function() { + return _t('Pricelist Report'); + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Get template to display report. + * + * @private + * @returns {Promise} + */ + _getHtml: function () { + return this._rpc({ + model: 'report.product.report_pricelist', + method: 'get_html', + kwargs: {context: this.context}, + }).then(result => { + this.reportHtml = result; + }); + }, + /** + * Reload report. + * + * @private + * @returns {Promise} + */ + _reload: function () { + return this._getHtml().then(() => { + this.$('.o_content').html(this.reportHtml); + }); + }, + /** + * Render search view and print button. + * + * @private + */ + _renderComponent: function () { + const $buttons = $(' + + + + + + + + + + +
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+
+ + + + + + + + + + + diff --git a/addons/product/static/tests/product_pricelist_report_test.js b/addons/product/static/tests/product_pricelist_report_test.js new file mode 100644 index 00000000..b9eac3cf --- /dev/null +++ b/addons/product/static/tests/product_pricelist_report_test.js @@ -0,0 +1,146 @@ +odoo.define('product.pricelist.report.tests', function (require) { +"use strict"; +const core = require('web.core'); +const GeneratePriceList = require('product.generate_pricelist').GeneratePriceList; +const NotificationService = require('web.NotificationService'); +const testUtils = require('web.test_utils'); +const createActionManager = testUtils.createActionManager; +const testUtilsMock = require('web.test_utils_mock'); + +QUnit.module('Product Pricelist', { + beforeEach: function () { + this.data = { + 'product.product': { + fields: { + id: {type: 'integer'} + }, + records: [{ + id: 42, + display_name: "Customizable Desk" + }] + }, + 'product.pricelist': { + fields: { + id: {type: 'integer'} + }, + records: [{ + id: 1, + display_name: "Public Pricelist" + }, { + id: 2, + display_name: "Test" + }] + } + }; + }, +}, function () { + QUnit.test('Pricelist Client Action', async function (assert) { + assert.expect(21); + + const self = this; + let Qty = [1, 5, 10]; // default quantities + testUtils.mock.patch(GeneratePriceList, { + _onFieldChanged: function (event) { + assert.step('field_changed'); + return this._super.apply(this, arguments); + }, + _onQtyChanged: function (event) { + assert.deepEqual(event.data.quantities, Qty.sort((a, b) => a - b), "changed quantity should be same."); + assert.step('qty_changed'); + return this._super.apply(this, arguments); + }, + }); + + const actionManager = await createActionManager({ + data: this.data, + mockRPC: function(route, args) { + if (route === '/web/dataset/call_kw/report.product.report_pricelist/get_html') { + return Promise.resolve(""); + } + return this._super(route, args); + }, + services: { + notification: NotificationService, + }, + }); + + await actionManager.doAction({ + id: 1, + name: 'Generate Pricelist', + tag: 'generate_pricelist', + type: 'ir.actions.client', + context: { + 'default_pricelist': 1, + 'active_ids': [42], + 'active_id': 42, + 'active_model': 'product.product' + } + }); + + // checking default pricelist + assert.strictEqual(actionManager.$('.o_field_many2one input').val(), "Public Pricelist", + "should have default pricelist"); + + // changing pricelist + await testUtils.fields.many2one.clickOpenDropdown("pricelist_id"); + await testUtils.fields.many2one.clickItem("pricelist_id", "Test"); + + // check wherther pricelist value has been updated or not. along with that check default quantities should be there. + assert.strictEqual(actionManager.$('.o_field_many2one input').val(), "Test", + "After pricelist change, the pricelist_id field should be updated"); + assert.strictEqual(actionManager.$('.o_badges > .badge').length, 3, + "There should be 3 default Quantities"); + + // existing quantity can not be added. + await testUtils.dom.click(actionManager.$('.o_add_qty')); + let notificationElement = document.body.querySelector('.o_notification_manager .o_notification.bg-info'); + assert.strictEqual(notificationElement.querySelector('.o_notification_content').textContent, + "Quantity already present (1).", "Existing Quantity can not be added"); + + // adding few more quantities to check. + actionManager.$('.o_product_qty').val(2); + Qty.push(2); + await testUtils.dom.click(actionManager.$('.o_add_qty')); + actionManager.$('.o_product_qty').val(3); + Qty.push(3); + await testUtils.dom.click(actionManager.$('.o_add_qty')); + + // should not be added more then 5 quantities. + actionManager.$('.o_product_qty').val(4); + await testUtils.dom.click(actionManager.$('.o_add_qty')); + + notificationElement = document.body.querySelector('.o_notification_manager .o_notification.bg-warning'); + assert.strictEqual(notificationElement.querySelector('.o_notification_content').textContent, + "At most 5 quantities can be displayed simultaneously. Remove a selected quantity to add others.", + "Can not add more then 5 quantities"); + + // removing all the quantities should work + Qty.pop(10); + await testUtils.dom.click(actionManager.$('.o_badges .badge:contains("10") .o_remove_qty')); + Qty.pop(5); + await testUtils.dom.click(actionManager.$('.o_badges .badge:contains("5") .o_remove_qty')); + Qty.pop(3); + await testUtils.dom.click(actionManager.$('.o_badges .badge:contains("3") .o_remove_qty')); + Qty.pop(2); + await testUtils.dom.click(actionManager.$('.o_badges .badge:contains("2") .o_remove_qty')); + Qty.pop(1); + await testUtils.dom.click(actionManager.$('.o_badges .badge:contains("1") .o_remove_qty')); + + assert.verifySteps([ + 'field_changed', + 'qty_changed', + 'qty_changed', + 'qty_changed', + 'qty_changed', + 'qty_changed', + 'qty_changed', + 'qty_changed' + ]); + + testUtils.mock.unpatch(GeneratePriceList); + actionManager.destroy(); + }); +} + +); +}); diff --git a/addons/product/static/xls/product_pricelist.xls b/addons/product/static/xls/product_pricelist.xls new file mode 100644 index 00000000..3eeac33c Binary files /dev/null and b/addons/product/static/xls/product_pricelist.xls differ diff --git a/addons/product/static/xls/product_supplierinfo.xls b/addons/product/static/xls/product_supplierinfo.xls new file mode 100644 index 00000000..50a165c6 Binary files /dev/null and b/addons/product/static/xls/product_supplierinfo.xls differ diff --git a/addons/product/static/xls/product_template.xls b/addons/product/static/xls/product_template.xls new file mode 100644 index 00000000..a4667b13 Binary files /dev/null and b/addons/product/static/xls/product_template.xls differ -- cgit v1.2.3