Browse Source

Add mobule pos_backend_partner

pull/227/head
hpar 7 years ago
parent
commit
69640a3fd0
  1. 53
      pos_backend_partner/README.rst
  2. 1
      pos_backend_partner/__init__.py
  3. 25
      pos_backend_partner/__manifest__.py
  4. 1
      pos_backend_partner/models/__init__.py
  5. 24
      pos_backend_partner/models/partner.py
  6. 17
      pos_backend_partner/static/src/js/back_partner.js
  7. 78
      pos_backend_partner/static/src/js/pos_partner.js
  8. 15
      pos_backend_partner/views/assets.xml
  9. 37
      pos_backend_partner/views/backend_partner.xml

53
pos_backend_partner/README.rst

@ -0,0 +1,53 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License
POS Backend Partner
===================
Choose a POS customer from the backend.
- Replace customer selection screen in POS by a backend view.
- Perf improvement : Full customer list is not downloaded anymore by the POS at startup.
- Benefit from the backend features: advanced search, easy to extend views, etc.
Configuration
=============
On each client's browser, during the first run, the permission for opening popup is prompted, it should be allowed.
Roadmap
=======
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/pos/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/pos/issues/new?body=module:%20pos_remove_pos_category%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Raphaël Reverdy <raphael.reverdy@akretion.com>
Maintainer
----------
.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
To contribute to this module, please visit http://odoo-community.org.

1
pos_backend_partner/__init__.py

@ -0,0 +1 @@
from . import models

25
pos_backend_partner/__manifest__.py

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Akretion (http://www.akretion.com).
# @author Raphaël Reverdy <raphael.reverdy@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Pos Backend customer",
"summary": "Choose point of sale customers in backend",
"version": "10.0.1.0.0",
"category": "Uncategorized",
"website": "www.akretion.com",
"author": " Akretion",
"license": "AGPL-3",
"application": False,
'installable': True,
"depends": [
"pos_backend_communication",
],
"data": [
'views/assets.xml',
'views/backend_partner.xml',
],
"qweb": [
]
}

1
pos_backend_partner/models/__init__.py

@ -0,0 +1 @@
from . import partner

24
pos_backend_partner/models/partner.py

@ -0,0 +1,24 @@
# coding: utf-8
# @author Raphael Reverdy <raphael.reverdy@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, api
class Partner(models.Model):
_inherit = "res.partner"
@api.multi
def select_in_pos_current_order(self):
"""Set point of sale customer to this partner.
Action called from view with self.id = a res.partner.
"""
return {
'type': 'ir.actions.act_tell_pos',
'payload': {
'type': 'partner.partner_selected',
'partner_id': self.id,
'name': self.name,
},
}

17
pos_backend_partner/static/src/js/back_partner.js

@ -0,0 +1,17 @@
'use strict';
odoo.define('pos_backend_partner.partner_back', function (require) {
var translation = require('web.translation');
var _t = translation._t;
var tools = require('pos_backend_communication.back');
if (tools.is_tied_to_pos()) {
tools.callbacks['partner.choose'] = function() {
//get focus with alert
//TODO: replace with notifications
alert(_t('Choose a customer'));
};
//tell the POS we are ready to receive
tools.sendMessage({type: 'partner.ready'});
}
});

78
pos_backend_partner/static/src/js/pos_partner.js

@ -0,0 +1,78 @@
'use strict';
odoo.define('pos_backend_partner.partner_pos', function (require) {
var tools = require('pos_backend_communication.tools');
var session = require('web.session');
var ProductScreenWidget = require('point_of_sale.screens');
var translation = require('web.translation');
var _t = translation._t;
var action_url = null;
var pos_instance = null;
function set_client(message)  {
var data = message.data;
var partner_info = {
'id': parseInt(data.id, 10),
'name': data.name
};
pos_instance.get('selectedOrder').set_client(partner_info);
alert(_t('Customer set')); //try to get the focus back
}
function open_backend(message) {
console.log('open backend partner');
//lookup action_id
action_url = action_url || session.rpc(
'/web/action/load', { "action_id":"pos_backend_partner.action_select_partner_pos"})
.then(function (e) { return e.id; });
action_url.then(function (action_id) {
var url = "/web#view_type=list&model=res.partner&action=" + action_id;
var msg = {'type': 'partner.choose'};
tools.open_page(url, msg, 'partner');
});
}
ProductScreenWidget.ActionpadWidget.include({
init: function(parent, options) {
this._super(parent, options);
pos_instance = this.pos;
},
renderElement: function() {
var self = this;
this._super();
this.$('.set-customer').unbind('click');
this.$('.set-customer').click(function(){
open_backend();
});
}
});
tools.callbacks['partner.partner_selected'] = set_client;
return {
callbacks: tools.callbacks
};
});
odoo.define('pos_backend_partner.prevent_model_load', function (require) {
// Prevent res.partner to be loaded at startup of the POS
// we load partners from the back office
//huge perf improvement server side AND client side AND network side
// we don't need it since the client is picked from the backoffice
var pos_models = require('point_of_sale.models');
var partnerModelId = null;
pos_models.PosModel.prototype.models.some(function (m, idx) {
if (m.model !== "res.partner")
return false;
partnerModelId = idx; //got her !
return true; //exit early
});
if (partnerModelId) {
pos_models.PosModel.prototype.models.splice(partnerModelId, 1);
//remove the model without changing the reference to the array
}
});

15
pos_backend_partner/views/assets.xml

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets" name="pos partner" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_backend_partner/static/src/js/pos_partner.js"></script>
</xpath>
</template>
<template id="assets_backend" name="back partner " inherit_id="web.assets_backend">
<xpath expr="." position="inside"> <!-- both back and POS -->
<script type="text/javascript" src="/pos_backend_partner/static/src/js/back_partner.js"></script>
</xpath>
</template>
</odoo>

37
pos_backend_partner/views/backend_partner.xml

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_partner_tree" model="ir.ui.view">
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree"/>
<field name="arch" type="xml">
<field name="display_name" position="before">
<button string="Choose"
type="object" name="select_in_pos_current_order"
help="Select as customer in point of sale"/>
</field>
</field>
</record>
<record id="view_partner_form" model="ir.ui.view">
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="display_name" position="after">
<button string="Choose"
type="object" name="select_in_pos_current_order"
help="Select as customer in point of sale"/>
</field>
</field>
</record>
<record id="action_select_partner_pos" model="ir.actions.act_window">
<field name="name">Client</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.partner</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('customer', '=', True)]</field>
<field name="context">{}</field>
</record>
</odoo>
Loading…
Cancel
Save