[IMP] stock_picking_auto_print: black, isort, prettier

This commit is contained in:
Bhavesh Odedra
2020-04-02 22:23:14 +05:30
parent c4c1344ad1
commit 1fcec0a73a
5 changed files with 112 additions and 90 deletions

View File

@@ -3,20 +3,15 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Direct Print',
'summary': 'Auto print when DO is ready',
'version': '11.0.1.0.0',
'license': 'AGPL-3',
'author': 'Open Source Integrators, Odoo Community Association (OCA)',
'category': 'Generic Modules/Base',
'website': 'http://www.opensourceintegrators.com',
'depends': [
'sale_stock',
'base_report_to_printer',
],
'data': [
'views/ir_action_report_view.xml'
],
'maintainers': ['bodedra'],
'installable': True,
"name": "Direct Print",
"summary": "Auto print when DO is ready",
"version": "11.0.1.0.0",
"license": "AGPL-3",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"category": "Generic Modules/Base",
"website": "http://www.opensourceintegrators.com",
"depends": ["sale_stock", "base_report_to_printer", ],
"data": ["views/ir_action_report_view.xml"],
"maintainers": ["bodedra"],
"installable": True,
}

View File

@@ -8,6 +8,6 @@ from odoo import fields, models
class IrActionsReport(models.Model):
_inherit = "ir.actions.report"
is_default_report = fields.Boolean('Is Default Report?')
country_id = fields.Many2one('res.country', string='Country')
company_id = fields.Many2one('res.company', string='Company')
is_default_report = fields.Boolean("Is Default Report?")
country_id = fields.Many2one("res.country", string="Country")
company_id = fields.Many2one("res.company", string="Company")

View File

@@ -10,37 +10,41 @@ class StockPicking(models.Model):
def _search_default_report(self, country_id=False, company_id=False):
report_id = False
report_action_pool = self.env['ir.actions.report']
domain = [('model', '=', 'stock.picking'),
('is_default_report', '=', True)]
fields = ['country_id', 'company_id']
report_action_pool = self.env["ir.actions.report"]
domain = [("model", "=", "stock.picking"), ("is_default_report", "=", True)]
fields = ["country_id", "company_id"]
stock_picking_reports = report_action_pool.search_read(domain, fields)
if country_id and company_id:
for value in stock_picking_reports:
if value.get('country_id') and value.get('company_id'):
if value.get('country_id')[0] == country_id and \
value.get('company_id')[0] == company_id:
return value['id']
if value.get("country_id") and value.get("company_id"):
if (
value.get("country_id")[0] == country_id
and value.get("company_id")[0] == company_id
):
return value["id"]
elif country_id:
for value in stock_picking_reports:
if value.get('country_id'):
if value.get('country_id')[0] == country_id:
return value['id']
if value.get("country_id"):
if value.get("country_id")[0] == country_id:
return value["id"]
elif company_id:
for value in stock_picking_reports:
if value.get('company_id'):
if value.get('company_id')[0] == company_id:
return value['id']
if value.get("company_id"):
if value.get("company_id")[0] == company_id:
return value["id"]
else:
report_id = self.env.ref(
'stock.action_report_picking').with_context(
landscape=True).report_action(self).get('id')
report_id = (
self.env.ref("stock.action_report_picking")
.with_context(landscape=True)
.report_action(self)
.get("id")
)
return report_id
@api.multi
def _stock_picking_default_auto_print_report(self):
user_company_id = self.env.user.company_id.id
report_action_pool = self.env['ir.actions.report']
report_action_pool = self.env["ir.actions.report"]
for picking in self.filtered(lambda p: p.sale_id):
default_report_id = False
# Check Partner country id
@@ -51,24 +55,26 @@ class StockPicking(models.Model):
if country_id and user_company_id:
# Filter report with Country and Company
default_report_id = picking._search_default_report(
country_id, user_company_id)
country_id, user_company_id
)
if not default_report_id and country_id:
# Filter report with Country
default_report_id = picking._search_default_report(
country_id=country_id)
country_id=country_id
)
if not default_report_id:
# Filter report with Company
default_report_id = picking._search_default_report(
company_id=user_company_id)
company_id=user_company_id
)
if not default_report_id:
# Search for default picking operation report
default_report_id = picking._search_default_report()
action_report = report_action_pool.browse(
default_report_id)
action_report = report_action_pool.browse(default_report_id)
try:
action_report.print_document(picking.id)
@@ -79,7 +85,7 @@ class StockPicking(models.Model):
@api.multi
def write(self, vals):
res = super(StockPicking, self).write(vals)
if 'date_done' in vals:
if "date_done" in vals:
self._stock_picking_default_auto_print_report()
return res
@@ -87,8 +93,9 @@ class StockPicking(models.Model):
def action_assign(self):
res = super(StockPicking, self).action_assign()
for picking in self:
if (picking.picking_type_code == 'outgoing' or
picking.location_dest_id.name == 'Output') and \
picking.state == 'assigned':
if (
picking.picking_type_code == "outgoing"
or picking.location_dest_id.name == "Output"
) and picking.state == "assigned":
picking._stock_picking_default_auto_print_report()
return res

View File

@@ -9,45 +9,60 @@ class StockPikcing(TransactionCase):
def setUp(self):
super(StockPikcing, self).setUp()
self.stock_location = self.env.ref('stock.stock_location_stock')
self.customer_location = self.env.ref('stock.stock_location_customers')
self.scrapped_location = self.env.ref('stock.stock_location_scrapped')
self.stock_location = self.env.ref("stock.stock_location_stock")
self.customer_location = self.env.ref("stock.stock_location_customers")
self.scrapped_location = self.env.ref("stock.stock_location_scrapped")
uom_unit = self.env.ref('product.product_uom_unit')
uom_unit = self.env.ref("product.product_uom_unit")
self.product_A = self.env['product.product'].create({
'name': 'Product A',
'type': 'product',
'list_price': 1.0,
'categ_id': self.env.ref('product.product_category_all').id,
'uom_id': uom_unit.id
})
self.product_A = self.env["product.product"].create(
{
"name": "Product A",
"type": "product",
"list_price": 1.0,
"categ_id": self.env.ref("product.product_category_all").id,
"uom_id": uom_unit.id,
}
)
self.country_us = self.env['res.country'].search(
[('code', 'like', 'US')], limit=1)
self.partner = self.env['res.partner'].create(
{'name': 'BOdedra', 'country_id': self.country_us.id})
self.country_us = self.env["res.country"].search(
[("code", "like", "US")], limit=1
)
self.partner = self.env["res.partner"].create(
{"name": "BOdedra", "country_id": self.country_us.id}
)
self.so = self.env['sale.order'].create({
'partner_id': self.partner.id,
'partner_invoice_id': self.partner.id,
'partner_shipping_id': self.partner.id,
'order_line': [(0, 0, {'name': self.product_A.name,
'product_id': self.product_A.id,
'product_uom_qty': 2,
'product_uom': self.product_A.uom_id.id,
'price_unit': self.product_A.list_price})],
'pricelist_id': self.env.ref('product.list0').id,
'picking_policy': 'direct',
})
self.so = self.env["sale.order"].create(
{
"partner_id": self.partner.id,
"partner_invoice_id": self.partner.id,
"partner_shipping_id": self.partner.id,
"order_line": [
(
0,
0,
{
"name": self.product_A.name,
"product_id": self.product_A.id,
"product_uom_qty": 2,
"product_uom": self.product_A.uom_id.id,
"price_unit": self.product_A.list_price,
},
)
],
"pricelist_id": self.env.ref("product.list0").id,
"picking_policy": "direct",
}
)
self.uom_unit = self.env.ref('product.product_uom_unit')
self.uom_unit = self.env.ref("product.product_uom_unit")
def test_stock_picking_auto_print(self):
""" Auto print when DO is ready or done
"""
self.env['stock.quant']._update_available_quantity(
self.product_A, self.stock_location, 2)
self.env["stock.quant"]._update_available_quantity(
self.product_A, self.stock_location, 2
)
self.so.action_confirm()
for picking in self.so.picking_ids:
picking.move_lines._do_unreserve()
@@ -56,15 +71,17 @@ class StockPikcing(TransactionCase):
picking.move_lines._do_unreserve()
# Made Delivery Slip report as a default report
deliveryslip_report = self.env['ir.actions.report'].search(
[('report_name', '=', 'stock.report_deliveryslip')])
deliveryslip_report = self.env["ir.actions.report"].search(
[("report_name", "=", "stock.report_deliveryslip")]
)
deliveryslip_report.write({'is_default_report': True})
deliveryslip_report.write({"is_default_report": True})
picking.action_assign()
# Remove country ID from Delivery Slip report
deliveryslip_report.write({'country_id': self.country_us.id,
'company_id': False})
deliveryslip_report.write(
{"country_id": self.country_us.id, "company_id": False}
)
picking.action_confirm()
picking.action_assign()
@@ -75,8 +92,8 @@ class StockPikcing(TransactionCase):
# Remove company ID from Delivery Slip report
deliveryslip_report.write(
{'company_id': self.env.user.company_id.id,
'country_id': False})
{"company_id": self.env.user.company_id.id, "country_id": False}
)
picking.action_confirm()
picking.action_assign()
@@ -84,8 +101,11 @@ class StockPikcing(TransactionCase):
picking.move_lines._do_unreserve()
deliveryslip_report.write(
{'company_id': self.env.user.company_id.id,
'country_id': self.country_us.id})
{
"company_id": self.env.user.company_id.id,
"country_id": self.country_us.id,
}
)
picking.action_confirm()
picking.action_assign()
picking.action_done()

View File

@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="country_company_default_report_xml_view" model="ir.ui.view">
<field name="name">country.company.default.report.form</field>
<field name="model">ir.actions.report</field>
<field name="inherit_id" ref="base_report_to_printer.act_report_xml_view"/>
<field name="inherit_id" ref="base_report_to_printer.act_report_xml_view" />
<field name="arch" type="xml">
<xpath expr="//page[@name='print']/group" position="after">
<group>
<field name="is_default_report"/>
<field name="country_id"/>
<field name="company_id"/>
<field name="is_default_report" />
<field name="country_id" />
<field name="company_id" />
</group>
</xpath>
</field>