mirror of
https://github.com/OCA/stock-logistics-reporting.git
synced 2025-02-16 17:13:21 +02:00
[IMP] stock_picking_comment_template: black, isort, prettier
This commit is contained in:
@@ -7,8 +7,7 @@
|
|||||||
"version": "12.0.1.0.0",
|
"version": "12.0.1.0.0",
|
||||||
"category": "Warehouse Management",
|
"category": "Warehouse Management",
|
||||||
"website": "https://github.com/OCA/stock-logistics-reporting",
|
"website": "https://github.com/OCA/stock-logistics-reporting",
|
||||||
"author": "C2i Change 2 improve,"
|
"author": "C2i Change 2 improve," "Odoo Community Association (OCA)",
|
||||||
"Odoo Community Association (OCA)",
|
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"depends": [
|
"depends": [
|
||||||
"stock",
|
"stock",
|
||||||
@@ -16,11 +15,11 @@
|
|||||||
"base_comment_template",
|
"base_comment_template",
|
||||||
],
|
],
|
||||||
"data": [
|
"data": [
|
||||||
'views/base_comment_template_view.xml',
|
"views/base_comment_template_view.xml",
|
||||||
'views/report_picking.xml',
|
"views/report_picking.xml",
|
||||||
'views/report_delivery_document.xml',
|
"views/report_delivery_document.xml",
|
||||||
"views/stock_picking_view.xml",
|
"views/stock_picking_view.xml",
|
||||||
'security/ir.model.access.csv',
|
"security/ir.model.access.csv",
|
||||||
],
|
],
|
||||||
'installable': True,
|
"installable": True,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ class ResPartner(models.Model):
|
|||||||
_inherit = "res.partner"
|
_inherit = "res.partner"
|
||||||
|
|
||||||
comment_template_id = fields.Many2one(
|
comment_template_id = fields.Many2one(
|
||||||
comodel_name='base.comment.template',
|
comodel_name="base.comment.template",
|
||||||
string='Picking conditions template',
|
string="Picking conditions template",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,29 +9,31 @@ class StockPicking(models.Model):
|
|||||||
|
|
||||||
_inherit = "stock.picking"
|
_inherit = "stock.picking"
|
||||||
|
|
||||||
comment_template1_id = fields.Many2one('base.comment.template',
|
comment_template1_id = fields.Many2one(
|
||||||
string='Top Comment Template')
|
"base.comment.template", string="Top Comment Template"
|
||||||
comment_template2_id = fields.Many2one('base.comment.template',
|
)
|
||||||
string='Bottom Comment Template')
|
comment_template2_id = fields.Many2one(
|
||||||
note1 = fields.Html('Top Comment')
|
"base.comment.template", string="Bottom Comment Template"
|
||||||
note2 = fields.Html('Bottom Comment')
|
)
|
||||||
|
note1 = fields.Html("Top Comment")
|
||||||
|
note2 = fields.Html("Bottom Comment")
|
||||||
|
|
||||||
@api.onchange('comment_template1_id')
|
@api.onchange("comment_template1_id")
|
||||||
def _set_note1(self):
|
def _set_note1(self):
|
||||||
comment = self.comment_template1_id
|
comment = self.comment_template1_id
|
||||||
if comment:
|
if comment:
|
||||||
self.note1 = comment.get_value(self.partner_id.id)
|
self.note1 = comment.get_value(self.partner_id.id)
|
||||||
|
|
||||||
@api.onchange('comment_template2_id')
|
@api.onchange("comment_template2_id")
|
||||||
def _set_note2(self):
|
def _set_note2(self):
|
||||||
comment = self.comment_template2_id
|
comment = self.comment_template2_id
|
||||||
if comment:
|
if comment:
|
||||||
self.note2 = comment.get_value(self.partner_id.id)
|
self.note2 = comment.get_value(self.partner_id.id)
|
||||||
|
|
||||||
@api.onchange('partner_id')
|
@api.onchange("partner_id")
|
||||||
def _onchange_partner_id(self):
|
def _onchange_partner_id(self):
|
||||||
comment_template = self.partner_id.comment_template_id
|
comment_template = self.partner_id.comment_template_id
|
||||||
if comment_template.position == 'before_lines':
|
if comment_template.position == "before_lines":
|
||||||
self.comment_template1_id = comment_template
|
self.comment_template1_id = comment_template
|
||||||
elif comment_template.position == 'after_lines':
|
elif comment_template.position == "after_lines":
|
||||||
self.comment_template2_id = comment_template
|
self.comment_template2_id = comment_template
|
||||||
|
|||||||
@@ -10,44 +10,50 @@ class TestStockPickingReport(TransactionCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestStockPickingReport, self).setUp()
|
super(TestStockPickingReport, self).setUp()
|
||||||
self.base_comment_model = self.env['base.comment.template']
|
self.base_comment_model = self.env["base.comment.template"]
|
||||||
self.before_comment = self._create_comment('before_lines')
|
self.before_comment = self._create_comment("before_lines")
|
||||||
self.after_comment = self._create_comment('after_lines')
|
self.after_comment = self._create_comment("after_lines")
|
||||||
self.partner = self.env['res.partner'].create({
|
self.partner = self.env["res.partner"].create({"name": "Partner Test"})
|
||||||
'name': 'Partner Test'
|
self.picking_model = self.env["stock.picking"]
|
||||||
})
|
self.picking = self.picking_model.create(
|
||||||
self.picking_model = self.env['stock.picking']
|
{
|
||||||
self.picking = self.picking_model.create({
|
"partner_id": self.partner.id,
|
||||||
'partner_id': self.partner.id,
|
"location_id": self.ref("stock.stock_location_stock"),
|
||||||
'location_id': self.ref('stock.stock_location_stock'),
|
"location_dest_id": self.ref("stock.stock_location_customers"),
|
||||||
'location_dest_id': self.ref('stock.stock_location_customers'),
|
"picking_type_id": self.ref("stock.picking_type_out"),
|
||||||
'picking_type_id': self.ref('stock.picking_type_out'),
|
"comment_template1_id": self.before_comment.id,
|
||||||
'comment_template1_id': self.before_comment.id,
|
"comment_template2_id": self.after_comment.id,
|
||||||
'comment_template2_id': self.after_comment.id
|
}
|
||||||
})
|
)
|
||||||
|
|
||||||
self.picking._set_note1()
|
self.picking._set_note1()
|
||||||
self.picking._set_note2()
|
self.picking._set_note2()
|
||||||
|
|
||||||
def _create_comment(self, position):
|
def _create_comment(self, position):
|
||||||
return self.base_comment_model.create({
|
return self.base_comment_model.create(
|
||||||
'name': 'Comment ' + position,
|
{
|
||||||
'position': position,
|
"name": "Comment " + position,
|
||||||
'text': 'Text ' + position
|
"position": position,
|
||||||
})
|
"text": "Text " + position,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def test_comments_in_picking(self):
|
def test_comments_in_picking(self):
|
||||||
res = self.env['ir.actions.report']._get_report_from_name(
|
res = (
|
||||||
'stock.report_picking'
|
self.env["ir.actions.report"]
|
||||||
).render_qweb_html(self.picking.ids)
|
._get_report_from_name("stock.report_picking")
|
||||||
|
.render_qweb_html(self.picking.ids)
|
||||||
|
)
|
||||||
self.assertRegexpMatches(str(res[0]), self.before_comment.text)
|
self.assertRegexpMatches(str(res[0]), self.before_comment.text)
|
||||||
self.assertRegexpMatches(str(res[0]), self.after_comment.text)
|
self.assertRegexpMatches(str(res[0]), self.after_comment.text)
|
||||||
|
|
||||||
def test_onchange_partner_id(self):
|
def test_onchange_partner_id(self):
|
||||||
self.partner.comment_template_id = self.after_comment.id
|
self.partner.comment_template_id = self.after_comment.id
|
||||||
new_picking = self.env['stock.picking'].new({
|
new_picking = self.env["stock.picking"].new(
|
||||||
'partner_id': self.partner.id,
|
{
|
||||||
})
|
"partner_id": self.partner.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
new_picking._onchange_partner_id()
|
new_picking._onchange_partner_id()
|
||||||
self.assertEqual(new_picking.comment_template2_id, self.after_comment)
|
self.assertEqual(new_picking.comment_template2_id, self.after_comment)
|
||||||
self.partner.comment_template_id = self.before_comment.id
|
self.partner.comment_template_id = self.before_comment.id
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|
||||||
<menuitem name="Document Comments"
|
<menuitem
|
||||||
id="menu_base_comment_template_picking"
|
name="Document Comments"
|
||||||
action="base_comment_template.action_base_comment_template"
|
id="menu_base_comment_template_picking"
|
||||||
parent="stock.menu_stock_config_settings"/>
|
action="base_comment_template.action_base_comment_template"
|
||||||
|
parent="stock.menu_stock_config_settings"
|
||||||
|
/>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|
||||||
<template id="report_delivery_document_comments"
|
<template
|
||||||
inherit_id="stock.report_delivery_document">
|
id="report_delivery_document_comments"
|
||||||
|
inherit_id="stock.report_delivery_document"
|
||||||
|
>
|
||||||
<xpath expr="//table[hasclass('table-sm')]" position="before">
|
<xpath expr="//table[hasclass('table-sm')]" position="before">
|
||||||
<p t-if="o.note1">
|
<p t-if="o.note1">
|
||||||
<span t-field="o.note1"/>
|
<span t-field="o.note1" />
|
||||||
</p>
|
</p>
|
||||||
</xpath>
|
</xpath>
|
||||||
<xpath expr="(//p)[position()=last()]" position="after">
|
<xpath expr="(//p)[position()=last()]" position="after">
|
||||||
<p t-if="o.note2">
|
<p t-if="o.note2">
|
||||||
<span t-field="o.note2"/>
|
<span t-field="o.note2" />
|
||||||
</p>
|
</p>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|
||||||
<template id="report_picking_document_comments"
|
<template id="report_picking_document_comments" inherit_id="stock.report_picking">
|
||||||
inherit_id="stock.report_picking">
|
|
||||||
<xpath expr="//table[hasclass('table-sm')]" position="before">
|
<xpath expr="//table[hasclass('table-sm')]" position="before">
|
||||||
<p t-if="o.note1">
|
<p t-if="o.note1">
|
||||||
<span t-field="o.note1"/>
|
<span t-field="o.note1" />
|
||||||
</p>
|
</p>
|
||||||
</xpath>
|
</xpath>
|
||||||
<xpath expr="//p[@t-field='o.note']" position="after">
|
<xpath expr="//p[@t-field='o.note']" position="after">
|
||||||
<p t-if="o.note2">
|
<p t-if="o.note2">
|
||||||
<span t-field="o.note2"/>
|
<span t-field="o.note2" />
|
||||||
</p>
|
</p>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -3,24 +3,30 @@
|
|||||||
<record model="ir.ui.view" id="stock_picking_form_add_comment">
|
<record model="ir.ui.view" id="stock_picking_form_add_comment">
|
||||||
<field name="name">stock.picking.form.comment</field>
|
<field name="name">stock.picking.form.comment</field>
|
||||||
<field name="model">stock.picking</field>
|
<field name="model">stock.picking</field>
|
||||||
<field name="inherit_id" ref="stock.view_picking_form"/>
|
<field name="inherit_id" ref="stock.view_picking_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//notebook" position="inside">
|
<xpath expr="//notebook" position="inside">
|
||||||
<page string="Comments" name="comments">
|
<page string="Comments" name="comments">
|
||||||
<p style="margin-top: 10px;">The comments will be displayed on the printed document. You can load a predefined template, write your own text or load a template and then modify it only for this document.</p>
|
<p
|
||||||
|
style="margin-top: 10px;"
|
||||||
|
>The comments will be displayed on the printed document. You can load a predefined template, write your own text or load a template and then modify it only for this document.</p>
|
||||||
<group string="Top Comments">
|
<group string="Top Comments">
|
||||||
<field name="comment_template1_id"
|
<field
|
||||||
string="Load a template"
|
name="comment_template1_id"
|
||||||
domain="[('position','=','before_lines')]"
|
string="Load a template"
|
||||||
context="{'default_position': 'before_lines'}"/>
|
domain="[('position','=','before_lines')]"
|
||||||
<field name="note1" nolabel="1" colspan="2"/>
|
context="{'default_position': 'before_lines'}"
|
||||||
|
/>
|
||||||
|
<field name="note1" nolabel="1" colspan="2" />
|
||||||
</group>
|
</group>
|
||||||
<group string="Bottom Comments">
|
<group string="Bottom Comments">
|
||||||
<field name="comment_template2_id"
|
<field
|
||||||
string="Load a template"
|
name="comment_template2_id"
|
||||||
context="{'default_position': 'after_lines'}"
|
string="Load a template"
|
||||||
domain="[('position','=','after_lines')]"/>
|
context="{'default_position': 'after_lines'}"
|
||||||
<field name="note2" nolabel="1" colspan="2"/>
|
domain="[('position','=','after_lines')]"
|
||||||
|
/>
|
||||||
|
<field name="note2" nolabel="1" colspan="2" />
|
||||||
</group>
|
</group>
|
||||||
</page>
|
</page>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
|||||||
Reference in New Issue
Block a user