Browse Source

[ADD] partner_label

12.0
Holger Brunn 7 years ago
parent
commit
72b1b43265
  1. 67
      partner_label/README.rst
  2. 4
      partner_label/__init__.py
  3. 20
      partner_label/__manifest__.py
  4. 5
      partner_label/models/__init__.py
  5. 50
      partner_label/models/base_config_settings.py
  6. 21
      partner_label/models/res_company.py
  7. 28
      partner_label/reports/res_partner.xml
  8. BIN
      partner_label/static/description/icon.png
  9. 4
      partner_label/tests/__init__.py
  10. 26
      partner_label/tests/test_partner_label.py
  11. 28
      partner_label/views/base_config_settings.xml

67
partner_label/README.rst

@ -0,0 +1,67 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
==============
Partner labels
==============
This module was written to allow users to print address labels for partners.
Configuration
=============
To configure this module, you need to:
#. go to `Settings / General settings`
#. scroll to header `Labels configuration`
#. change width, height, padding and margin to fit your label stickers, if necessary change the paper format
#. you can preview your changes by pressing the `Preview` button
Usage
=====
#. mark partners
#. print your labels
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/134/10.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/partner-contact/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.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Holger Brunn <hbrunn@therp.nl>
Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:community@mail.odoo.com>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues.
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://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 https://odoo-community.org.

4
partner_label/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models

20
partner_label/__manifest__.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Partner labels",
"version": "10.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Base",
"summary": "Print partner labels",
"depends": [
'base_setup',
'report',
],
"data": [
"views/base_config_settings.xml",
"reports/res_partner.xml",
],
"installable": True,
}

5
partner_label/models/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import res_company
from . import base_config_settings

50
partner_label/models/base_config_settings.py

@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import api, fields, models
class BaseConfigSettings(models.TransientModel):
_inherit = 'base.config.settings'
partner_labels_width = fields.Float(
related='company_id.partner_labels_width', required=True,
)
partner_labels_height = fields.Float(
related='company_id.partner_labels_height', required=True,
)
partner_labels_padding = fields.Float(
related='company_id.partner_labels_padding', required=True,
)
partner_labels_margin = fields.Float(
related='company_id.partner_labels_margin', required=True,
)
partner_labels_paperformat_id = fields.Many2one(
'report.paperformat', string='Paperformat', required=True,
default=lambda self: self.env.ref(
'partner_label.report_res_partner_label'
).paperformat_id,
compute='_compute_partner_labels_paperformat_id',
inverse='_inverse_partner_labels_paperformat_id',
)
@api.multi
def _compute_partner_labels_paperformat_id(self):
for this in self:
this.partner_labels_paperformat_id = self.env.ref(
'partner_label.report_res_partner_label'
).paperformat_id
@api.multi
def _inverse_partner_labels_paperformat_id(self):
for this in self:
self.env.ref(
'partner_label.report_res_partner_label'
).paperformat_id = this.partner_labels_paperformat_id
@api.multi
def action_partner_labels_preview(self):
return self.env['report'].get_action(
self.env['res.partner'].search([], limit=100),
'partner_label.view_res_partner_label',
)

21
partner_label/models/res_company.py

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import fields, models
class ResCompany(models.Model):
_inherit = 'res.company'
partner_labels_width = fields.Float(
'Width', default=60, help='Width in millimeters', required=True,
)
partner_labels_height = fields.Float(
'Height', default=42.3, help='Height in millimeters', required=True,
)
partner_labels_padding = fields.Float(
'Padding', default=5, help='Padding in millimeters', required=True,
)
partner_labels_margin = fields.Float(
'Margin', default=1, help='Margin in millimeters', required=True,
)

28
partner_label/reports/res_partner.xml

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<template id="view_res_partner_label">
<t t-raw="'&lt;base href=%s&gt;' % base_url"/>
&lt;!DOCTYPE html&gt;
<html>
<head>
<meta charset="utf-8"/>
</head>
<body class="container">
<div class="page">
<t t-foreach="docs.with_context(show_address=True)" t-as="this">
<div t-attf-style="height: {{this.company_id.partner_labels_height}}mm; width: {{this.company_id.partner_labels_width}}mm; padding: {{this.company_id.partner_labels_padding}}mm; margin: {{this.company_id.partner_labels_margin}}mm; display: inline-block; overflow: hidden;">
<div t-esc="this.name_get()[0][1]" style="white-space: pre-line;" />
</div>
</t>
</div>
</body>
</html>
</template>
<report id="report_res_partner_label"
string="Labels"
model="res.partner"
name="partner_label.view_res_partner_label"
report_type="qweb-pdf"
paperformat="report.paperformat_euro"
/>
</odoo>

BIN
partner_label/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

4
partner_label/tests/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_partner_label

26
partner_label/tests/test_partner_label.py

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase
class TestPartnerLabel(TransactionCase):
def test_partner_label(self):
settings = self.env['base.config.settings'].create({})
self.assertItemsEqual(
settings.action_partner_labels_preview()['context']['active_ids'],
self.env['res.partner'].search([], limit=100).ids,
)
self.assertEqual(
settings.partner_labels_paperformat_id,
self.env.ref('partner_label.report_res_partner_label')
.paperformat_id
)
settings.partner_labels_paperformat_id = self.env.ref(
'report.paperformat_us'
).id,
self.assertEqual(
self.env.ref('partner_label.report_res_partner_label')
.paperformat_id,
self.env.ref('report.paperformat_us')
)

28
partner_label/views/base_config_settings.xml

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="view_general_configuration" model="ir.ui.view">
<field name="model">base.config.settings</field>
<field name="inherit_id" ref="base_setup.view_general_configuration" />
<field name="arch" type="xml">
<group name="report" position="after">
<group name="partner_labels" string="Labels configuration">
<label for="partner_labels_width" />
<div><field name="partner_labels_width" class="oe_inline" /> mm</div>
<label for="partner_labels_height" />
<div><field name="partner_labels_height" class="oe_inline" /> mm</div>
<label for="partner_labels_margin" />
<div><field name="partner_labels_margin" class="oe_inline" /> mm</div>
<label for="partner_labels_padding" />
<div><field name="partner_labels_padding" class="oe_inline" /> mm</div>
<label for="partner_labels_paperformat_id" />
<div>
<field name="partner_labels_paperformat_id" class="oe_inline" />
<button type="object" name="action_partner_labels_preview" string="Preview" />
</div>
</group>
</group>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save