Jordi Ballester Alomar
6 years ago
committed by
OCA-git-bot
6 changed files with 102 additions and 32 deletions
-
5barcode_action/__init__.py
-
5barcode_action/__manifest__.py
-
17barcode_action/demo/barcode_action_demo.xml
-
1barcode_action/models/__init__.py
-
31barcode_action/models/res_partner.py
-
49barcode_action/readme/USAGE.rst
@ -1,5 +1,2 @@ |
|||
# Copyright 2017 Creu Blanca |
|||
# Copyright 2017 Eficent Business and IT Consulting Services, S.L. |
|||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). |
|||
|
|||
from . import wizard |
|||
from . import models |
@ -0,0 +1,17 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<data> |
|||
<act_window id="res_partner_find" |
|||
name="Find Partner" |
|||
res_model="barcode.action" |
|||
view_mode="form" |
|||
view_type="form" |
|||
context="{'default_model': 'res.partner', 'default_method': 'find_res_partner_by_ref_using_barcode'}" |
|||
target="new"/> |
|||
|
|||
<menuitem id="menu_orders_customers" name="Find partners" |
|||
action="res_partner_find" |
|||
parent="base.menu_administration"/> |
|||
|
|||
</data> |
|||
</odoo> |
@ -0,0 +1 @@ |
|||
from . import res_partner |
@ -0,0 +1,31 @@ |
|||
# Copyright 2018 Creu Blanca |
|||
# Copyright 2018 Eficent Business and IT Consulting Services, S.L. |
|||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). |
|||
import json |
|||
from odoo import api, models, _ |
|||
from odoo.tools.safe_eval import safe_eval |
|||
|
|||
|
|||
class ResPartner(models.Model): |
|||
_inherit = 'res.partner' |
|||
|
|||
@api.multi |
|||
def find_res_partner_by_ref_using_barcode(self, barcode): |
|||
partner = self.search([('ref', '=', barcode)], limit=1) |
|||
if not partner: |
|||
action = self.env.ref('res_partner_find') |
|||
result = action.read()[0] |
|||
context = safe_eval(result['context']) |
|||
context.update({ |
|||
'default_state': 'warning', |
|||
'default_status': _('Partner with Internal Reference ' |
|||
'%s cannot be found') % barcode |
|||
}) |
|||
result['context'] = json.dumps(context) |
|||
return result |
|||
action = self.env.ref('base.action_partner_form') |
|||
result = action.read()[0] |
|||
res = self.env.ref('base.view_partner_form', False) |
|||
result['views'] = [(res and res.id or False, 'form')] |
|||
result['res_id'] = partner.id |
|||
return result |
Write
Preview
Loading…
Cancel
Save
Reference in new issue