{"action":"created","comment":{"url":"https://api.github.com/repos/odoo/odoo/pulls/comments/48901575","id":48901575,"diff_hunk":"@@ -0,0 +1,238 @@\n+# -*- coding: utf-8 -*-\n+# Part of Odoo. See LICENSE file for full copyright and licensing details.\n+import time\n+\n+from odoo import api, fields, models, _\n+from odoo.exceptions import UserError\n+\n+\n+class PosSession(models.Model):\n+    _name = 'pos.session'\n+    _order = 'id desc'\n+\n+    POS_SESSION_STATE = [\n+        ('opening_control', 'Opening Control'),  # Signal open\n+        ('opened', 'In Progress'),               # Signal closing\n+        ('closing_control', 'Closing Control'),  # Signal close\n+        ('closed', 'Closed & Posted'),\n+    ]\n+\n+    def _confirm_orders(self):\n+        PosOrder = self.env['pos.order']\n+        for session in self:\n+            company_id = session.config_id.journal_id.company_id.id\n+            local_context = dict(self.env.context, force_company=company_id)\n+            orders = session.order_ids.filtered(lambda order: order.state == 'paid')\n+            move = PosOrder.with_context(local_context)._create_account_move(session.start_at, session.name, session.config_id.journal_id.id, company_id)\n+            orders.with_context(local_context)._create_account_move_line(session, move)\n+            for order in session.order_ids.filtered(lambda o: o.state != 'done'):\n+                if order.state not in ('paid', 'invoiced'):\n+                    raise UserError(_(\"You cannot confirm all orders of this session, because they have not the 'paid' status\"))\n+                order.signal_workflow('done')\n+\n+    config_id = fields.Many2one(\n+        'pos.config', string='Point of Sale',\n+        help=\"The physical point of sale you will use.\",\n+        required=True,\n+        index=True,\n+        domain=\"[('state', '=', 'active')]\")\n+    name = fields.Char(string='Session ID', required=True, readonly=True, default='/')\n+    user_id = fields.Many2one(\n+        'res.users', string='Responsible',\n+        required=True,\n+        index=True,\n+        readonly=True,\n+        states={'opening_control': [('readonly', False)]},\n+        default=lambda self: self.env.uid)\n+    currency_id = fields.Many2one('res.currency', related='config_id.currency_id', string=\"Currency\")\n+    start_at = fields.Datetime(string='Opening Date', readonly=True)\n+    stop_at = fields.Datetime(string='Closing Date', readonly=True, copy=False)\n+\n+    state = fields.Selection(\n+        POS_SESSION_STATE, string='Status',\n+        required=True, readonly=True,\n+        index=True, copy=False, default='opening_control')\n+    rescue = fields.Boolean(\n+        string='Rescue session', readonly=True,\n+        help=\"Auto-generated session for orphan orders, ignored in constraints\")\n+\n+    sequence_number = fields.Integer(string='Order Sequence Number', help='A sequence number that is incremented with each order', default=1)\n+    login_number = fields.Integer(string='Login Sequence Number', help='A sequence number that is incremented each time a user resumes the pos session', default=0)\n+\n+    cash_control = fields.Boolean(compute='_compute_cash_all',    string='Has Cash Control')\n+    cash_journal_id = fields.Many2one('account.journal', compute='_compute_cash_all', string='Cash Journal', store=True)\n+    cash_register_id = fields.Many2one('account.bank.statement', compute='_compute_cash_all', string='Cash Register', store=True)\n+\n+    cash_register_balance_end_real = fields.Monetary(\n+        related='cash_register_id.balance_end_real',\n+        string=\"Ending Balance\",\n+        help=\"Total of closing cash control lines.\",\n+        readonly=True)\n+    cash_register_balance_start = fields.Monetary(\n+        related='cash_register_id.balance_start',\n+        string=\"Starting Balance\",\n+        help=\"Total of opening cash control lines.\",\n+        readonly=True)\n+    cash_register_total_entry_encoding = fields.Monetary(\n+        related='cash_register_id.total_entry_encoding',\n+        string='Total Cash Transaction',\n+        readonly=True,\n+        help=\"Total of all paid sale orders\")\n+    cash_register_balance_end = fields.Monetary(\n+        related='cash_register_id.balance_end',\n+        digits=0,\n+        string=\"Theoretical Closing Balance\",\n+        help=\"Sum of opening balance and transactions.\",\n+        readonly=True)\n+    cash_register_difference = fields.Monetary(\n+        related='cash_register_id.difference',\n+        string='Difference',\n+        help=\"Difference between the theoretical closing balance and the real closing balance.\",\n+        readonly=True)\n+\n+    journal_ids = fields.Many2many(\n+        'account.journal',\n+        related='config_id.journal_ids',\n+        readonly=True,\n+        string='Available Payment Methods')\n+    order_ids = fields.One2many('pos.order', 'session_id',  string='Orders')\n+    statement_ids = fields.One2many('account.bank.statement', 'pos_session_id', string='Bank Statement', readonly=True)\n+\n+    _sql_constraints = [('uniq_name', 'unique(name)', _(\"The name of this POS Session must be unique !\"))]\n+\n+    @api.depends('cash_control', 'cash_journal_id')\n+    def _compute_cash_all(self):\n+        for session in self:\n+            session.cash_journal_id = session.cash_register_id = session.cash_control = False\n+            if session.config_id.cash_control:\n+                for statement in session.statement_ids:\n+                    if statement.journal_id.type == 'cash':\n+                        session.cash_control = True\n+                        session.cash_journal_id = statement.journal_id.id\n+                        session.cash_register_id = statement.id\n+                if not session.cash_control:\n+                    raise UserError(_(\"Cash control can only be applied to cash journals.\"))\n+\n+    @api.constrains('user_id', 'state')\n+    def _check_unicity(self):\n+        # open if there is no session in 'opening_control', 'opened', 'closing_control' for one user\n+        if self.search_count([('state', 'not in', ('closed', 'closing_control')), ('user_id', '=', self.user_id.id)]) > 1:","path":"addons/point_of_sale/models/pos_session.py","position":119,"original_position":119,"commit_id":"c8c4248adea6f0036a6c6b04fdbe1d11ec755b89","original_commit_id":"c8c4248adea6f0036a6c6b04fdbe1d11ec755b89","user":{"login":"WHPODOO","id":14940179,"avatar_url":"https://avatars.githubusercontent.com/u/14940179?v=3","gravatar_id":"","url":"https://api.github.com/users/WHPODOO","html_url":"https://github.com/WHPODOO","followers_url":"https://api.github.com/users/WHPODOO/followers","following_url":"https://api.github.com/users/WHPODOO/following{/other_user}","gists_url":"https://api.github.com/users/WHPODOO/gists{/gist_id}","starred_url":"https://api.github.com/users/WHPODOO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WHPODOO/subscriptions","organizations_url":"https://api.github.com/users/WHPODOO/orgs","repos_url":"https://api.github.com/users/WHPODOO/repos","events_url":"https://api.github.com/users/WHPODOO/events{/privacy}","received_events_url":"https://api.github.com/users/WHPODOO/received_events","type":"User","site_admin":false},"body":"you can use read group","created_at":"2016-01-05T21:54:43Z","updated_at":"2016-01-05T21:54:43Z","html_url":"https://github.com/odoo/odoo/pull/10259#discussion_r48901575","pull_request_url":"https://api.github.com/repos/odoo/odoo/pulls/10259","_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments/48901575"},"html":{"href":"https://github.com/odoo/odoo/pull/10259#discussion_r48901575"},"pull_request":{"href":"https://api.github.com/repos/odoo/odoo/pulls/10259"}}},"pull_request":{"url":"https://api.github.com/repos/odoo/odoo/pulls/10259","id":54887748,"html_url":"https://github.com/odoo/odoo/pull/10259","diff_url":"https://github.com/odoo/odoo/pull/10259.diff","patch_url":"https://github.com/odoo/odoo/pull/10259.patch","issue_url":"https://api.github.com/repos/odoo/odoo/issues/10259","number":10259,"state":"open","locked":false,"title":"[point of sale] migrate to new api","user":{"login":"dka-odoo","id":7599807,"avatar_url":"https://avatars.githubusercontent.com/u/7599807?v=3","gravatar_id":"","url":"https://api.github.com/users/dka-odoo","html_url":"https://github.com/dka-odoo","followers_url":"https://api.github.com/users/dka-odoo/followers","following_url":"https://api.github.com/users/dka-odoo/following{/other_user}","gists_url":"https://api.github.com/users/dka-odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/dka-odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dka-odoo/subscriptions","organizations_url":"https://api.github.com/users/dka-odoo/orgs","repos_url":"https://api.github.com/users/dka-odoo/repos","events_url":"https://api.github.com/users/dka-odoo/events{/privacy}","received_events_url":"https://api.github.com/users/dka-odoo/received_events","type":"User","site_admin":false},"body":"Task - https://www.odoo.com/web#id=13556&view_type=form&model=project.task&action=327&menu_id=4720\r\n\r\npad - https://pad.odoo.com/p/r.SkQZ55ogZNFlskX3","created_at":"2016-01-01T05:30:36Z","updated_at":"2016-01-05T21:54:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2fc18d9bf1f4b79aa7e030f8d69fa78eac8c0272","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/odoo/odoo/pulls/10259/commits","review_comments_url":"https://api.github.com/repos/odoo/odoo/pulls/10259/comments","review_comment_url":"https://api.github.com/repos/odoo/odoo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/odoo/odoo/issues/10259/comments","statuses_url":"https://api.github.com/repos/odoo/odoo/statuses/c8c4248adea6f0036a6c6b04fdbe1d11ec755b89","head":{"label":"odoo-dev:master-pos-new-api-dka","ref":"master-pos-new-api-dka","sha":"c8c4248adea6f0036a6c6b04fdbe1d11ec755b89","user":{"login":"odoo-dev","id":7466976,"avatar_url":"https://avatars.githubusercontent.com/u/7466976?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo-dev","html_url":"https://github.com/odoo-dev","followers_url":"https://api.github.com/users/odoo-dev/followers","following_url":"https://api.github.com/users/odoo-dev/following{/other_user}","gists_url":"https://api.github.com/users/odoo-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo-dev/subscriptions","organizations_url":"https://api.github.com/users/odoo-dev/orgs","repos_url":"https://api.github.com/users/odoo-dev/repos","events_url":"https://api.github.com/users/odoo-dev/events{/privacy}","received_events_url":"https://api.github.com/users/odoo-dev/received_events","type":"Organization","site_admin":false},"repo":{"id":19853934,"name":"odoo","full_name":"odoo-dev/odoo","owner":{"login":"odoo-dev","id":7466976,"avatar_url":"https://avatars.githubusercontent.com/u/7466976?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo-dev","html_url":"https://github.com/odoo-dev","followers_url":"https://api.github.com/users/odoo-dev/followers","following_url":"https://api.github.com/users/odoo-dev/following{/other_user}","gists_url":"https://api.github.com/users/odoo-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo-dev/subscriptions","organizations_url":"https://api.github.com/users/odoo-dev/orgs","repos_url":"https://api.github.com/users/odoo-dev/repos","events_url":"https://api.github.com/users/odoo-dev/events{/privacy}","received_events_url":"https://api.github.com/users/odoo-dev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/odoo-dev/odoo","description":"RD Dev Repository","fork":true,"url":"https://api.github.com/repos/odoo-dev/odoo","forks_url":"https://api.github.com/repos/odoo-dev/odoo/forks","keys_url":"https://api.github.com/repos/odoo-dev/odoo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odoo-dev/odoo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odoo-dev/odoo/teams","hooks_url":"https://api.github.com/repos/odoo-dev/odoo/hooks","issue_events_url":"https://api.github.com/repos/odoo-dev/odoo/issues/events{/number}","events_url":"https://api.github.com/repos/odoo-dev/odoo/events","assignees_url":"https://api.github.com/repos/odoo-dev/odoo/assignees{/user}","branches_url":"https://api.github.com/repos/odoo-dev/odoo/branches{/branch}","tags_url":"https://api.github.com/repos/odoo-dev/odoo/tags","blobs_url":"https://api.github.com/repos/odoo-dev/odoo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odoo-dev/odoo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odoo-dev/odoo/git/refs{/sha}","trees_url":"https://api.github.com/repos/odoo-dev/odoo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odoo-dev/odoo/statuses/{sha}","languages_url":"https://api.github.com/repos/odoo-dev/odoo/languages","stargazers_url":"https://api.github.com/repos/odoo-dev/odoo/stargazers","contributors_url":"https://api.github.com/repos/odoo-dev/odoo/contributors","subscribers_url":"https://api.github.com/repos/odoo-dev/odoo/subscribers","subscription_url":"https://api.github.com/repos/odoo-dev/odoo/subscription","commits_url":"https://api.github.com/repos/odoo-dev/odoo/commits{/sha}","git_commits_url":"https://api.github.com/repos/odoo-dev/odoo/git/commits{/sha}","comments_url":"https://api.github.com/repos/odoo-dev/odoo/comments{/number}","issue_comment_url":"https://api.github.com/repos/odoo-dev/odoo/issues/comments{/number}","contents_url":"https://api.github.com/repos/odoo-dev/odoo/contents/{+path}","compare_url":"https://api.github.com/repos/odoo-dev/odoo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odoo-dev/odoo/merges","archive_url":"https://api.github.com/repos/odoo-dev/odoo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odoo-dev/odoo/downloads","issues_url":"https://api.github.com/repos/odoo-dev/odoo/issues{/number}","pulls_url":"https://api.github.com/repos/odoo-dev/odoo/pulls{/number}","milestones_url":"https://api.github.com/repos/odoo-dev/odoo/milestones{/number}","notifications_url":"https://api.github.com/repos/odoo-dev/odoo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odoo-dev/odoo/labels{/name}","releases_url":"https://api.github.com/repos/odoo-dev/odoo/releases{/id}","created_at":"2014-05-16T11:16:19Z","updated_at":"2015-12-23T12:18:18Z","pushed_at":"2016-01-05T17:29:57Z","git_url":"git://github.com/odoo-dev/odoo.git","ssh_url":"git@github.com:odoo-dev/odoo.git","clone_url":"https://github.com/odoo-dev/odoo.git","svn_url":"https://github.com/odoo-dev/odoo","homepage":"https://www.odoo.com","size":1189114,"stargazers_count":65,"watchers_count":65,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":27,"mirror_url":null,"open_issues_count":0,"forks":27,"open_issues":0,"watchers":65,"default_branch":"master"}},"base":{"label":"odoo:master","ref":"master","sha":"c9ed8aec914409deff7ff8d7d44254b3e9854dff","user":{"login":"odoo","id":6368483,"avatar_url":"https://avatars.githubusercontent.com/u/6368483?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo","html_url":"https://github.com/odoo","followers_url":"https://api.github.com/users/odoo/followers","following_url":"https://api.github.com/users/odoo/following{/other_user}","gists_url":"https://api.github.com/users/odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo/subscriptions","organizations_url":"https://api.github.com/users/odoo/orgs","repos_url":"https://api.github.com/users/odoo/repos","events_url":"https://api.github.com/users/odoo/events{/privacy}","received_events_url":"https://api.github.com/users/odoo/received_events","type":"Organization","site_admin":false},"repo":{"id":19745004,"name":"odoo","full_name":"odoo/odoo","owner":{"login":"odoo","id":6368483,"avatar_url":"https://avatars.githubusercontent.com/u/6368483?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo","html_url":"https://github.com/odoo","followers_url":"https://api.github.com/users/odoo/followers","following_url":"https://api.github.com/users/odoo/following{/other_user}","gists_url":"https://api.github.com/users/odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo/subscriptions","organizations_url":"https://api.github.com/users/odoo/orgs","repos_url":"https://api.github.com/users/odoo/repos","events_url":"https://api.github.com/users/odoo/events{/privacy}","received_events_url":"https://api.github.com/users/odoo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/odoo/odoo","description":"Odoo (formerly OpenERP). Open Source Apps To Grow Your Business.","fork":false,"url":"https://api.github.com/repos/odoo/odoo","forks_url":"https://api.github.com/repos/odoo/odoo/forks","keys_url":"https://api.github.com/repos/odoo/odoo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odoo/odoo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odoo/odoo/teams","hooks_url":"https://api.github.com/repos/odoo/odoo/hooks","issue_events_url":"https://api.github.com/repos/odoo/odoo/issues/events{/number}","events_url":"https://api.github.com/repos/odoo/odoo/events","assignees_url":"https://api.github.com/repos/odoo/odoo/assignees{/user}","branches_url":"https://api.github.com/repos/odoo/odoo/branches{/branch}","tags_url":"https://api.github.com/repos/odoo/odoo/tags","blobs_url":"https://api.github.com/repos/odoo/odoo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odoo/odoo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odoo/odoo/git/refs{/sha}","trees_url":"https://api.github.com/repos/odoo/odoo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odoo/odoo/statuses/{sha}","languages_url":"https://api.github.com/repos/odoo/odoo/languages","stargazers_url":"https://api.github.com/repos/odoo/odoo/stargazers","contributors_url":"https://api.github.com/repos/odoo/odoo/contributors","subscribers_url":"https://api.github.com/repos/odoo/odoo/subscribers","subscription_url":"https://api.github.com/repos/odoo/odoo/subscription","commits_url":"https://api.github.com/repos/odoo/odoo/commits{/sha}","git_commits_url":"https://api.github.com/repos/odoo/odoo/git/commits{/sha}","comments_url":"https://api.github.com/repos/odoo/odoo/comments{/number}","issue_comment_url":"https://api.github.com/repos/odoo/odoo/issues/comments{/number}","contents_url":"https://api.github.com/repos/odoo/odoo/contents/{+path}","compare_url":"https://api.github.com/repos/odoo/odoo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odoo/odoo/merges","archive_url":"https://api.github.com/repos/odoo/odoo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odoo/odoo/downloads","issues_url":"https://api.github.com/repos/odoo/odoo/issues{/number}","pulls_url":"https://api.github.com/repos/odoo/odoo/pulls{/number}","milestones_url":"https://api.github.com/repos/odoo/odoo/milestones{/number}","notifications_url":"https://api.github.com/repos/odoo/odoo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odoo/odoo/labels{/name}","releases_url":"https://api.github.com/repos/odoo/odoo/releases{/id}","created_at":"2014-05-13T15:38:58Z","updated_at":"2016-01-05T20:55:36Z","pushed_at":"2016-01-05T17:46:08Z","git_url":"git://github.com/odoo/odoo.git","ssh_url":"git@github.com:odoo/odoo.git","clone_url":"https://github.com/odoo/odoo.git","svn_url":"https://github.com/odoo/odoo","homepage":"https://www.odoo.com","size":1276520,"stargazers_count":3591,"watchers_count":3591,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3317,"mirror_url":null,"open_issues_count":2946,"forks":3317,"open_issues":2946,"watchers":3591,"default_branch":"9.0"}},"_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/10259"},"html":{"href":"https://github.com/odoo/odoo/pull/10259"},"issue":{"href":"https://api.github.com/repos/odoo/odoo/issues/10259"},"comments":{"href":"https://api.github.com/repos/odoo/odoo/issues/10259/comments"},"review_comments":{"href":"https://api.github.com/repos/odoo/odoo/pulls/10259/comments"},"review_comment":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/odoo/odoo/pulls/10259/commits"},"statuses":{"href":"https://api.github.com/repos/odoo/odoo/statuses/c8c4248adea6f0036a6c6b04fdbe1d11ec755b89"}}}}