Browse Source

[REF] pos_order_to_sale_order: Black python code

pull/441/head
Sylvain LE GAL 5 years ago
parent
commit
f8b940e4df
  1. 34
      pos_order_to_sale_order/__openerp__.py
  2. 20
      pos_order_to_sale_order/models/pos_config.py
  3. 99
      pos_order_to_sale_order/models/sale_order.py

34
pos_order_to_sale_order/__openerp__.py

@ -4,25 +4,19 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'PoS Order To Sale Order',
'version': '8.0.3.0.0',
'author': 'GRAP,Odoo Community Association (OCA)',
'category': 'Point Of Sale',
'license': 'AGPL-3',
'depends': [
'point_of_sale',
],
'maintainers': ['legalsylvain'],
'development_status': "Production/Stable",
'website': 'https://odoo-community.org/',
'data': [
'views/view_pos_config.xml',
'views/pos_order_to_sale_order.xml',
],
'demo': [
'demo/res_groups.xml',
],
'qweb': [
'static/src/xml/pos_order_to_sale_order.xml',
"name": "PoS Order To Sale Order",
"version": "8.0.3.0.0",
"author": "GRAP,Odoo Community Association (OCA)",
"category": "Point Of Sale",
"license": "AGPL-3",
"depends": ["point_of_sale",],
"maintainers": ["legalsylvain"],
"development_status": "Production/Stable",
"website": "https://odoo-community.org/",
"data": [
"views/view_pos_config.xml",
"views/pos_order_to_sale_order.xml",
],
"demo": ["demo/res_groups.xml",],
"qweb": ["static/src/xml/pos_order_to_sale_order.xml",],
}

20
pos_order_to_sale_order/models/pos_config.py

@ -7,21 +7,27 @@ from openerp import models, fields
class PosConfig(models.Model):
_inherit = 'pos.config'
_inherit = "pos.config"
iface_create_draft_sale_order = fields.Boolean(
string='Create Draft Sale Orders', default=True,
string="Create Draft Sale Orders",
default=True,
help="If checked, the cashier will have the possibility to create"
" a draft Sale Order, based on the current draft PoS Order.")
" a draft Sale Order, based on the current draft PoS Order.",
)
iface_create_confirmed_sale_order = fields.Boolean(
string='Create Confirmed Sale Orders', default=True,
string="Create Confirmed Sale Orders",
default=True,
help="If checked, the cashier will have the possibility to create"
" a confirmed Sale Order, based on the current draft PoS Order.")
" a confirmed Sale Order, based on the current draft PoS Order.",
)
iface_create_delivered_sale_order = fields.Boolean(
string='Create Delivered Sale Orders', default=True,
string="Create Delivered Sale Orders",
default=True,
help="If checked, the cashier will have the possibility to create"
" a confirmed sale Order, based on the current draft PoS Order.\n"
" the according picking will be marked as delivered. Only invoices"
" process will be possible.")
" process will be possible.",
)

99
pos_order_to_sale_order/models/sale_order.py

@ -7,68 +7,85 @@ from openerp import models, api, _
class SaleOrder(models.Model):
_inherit = 'sale.order'
_inherit = "sale.order"
@api.model
def _prepare_order_field_from_pos(self, order_data):
session_obj = self.env['pos.session']
session = session_obj.browse(order_data['pos_session_id'])
res = self.onchange_partner_id(order_data['partner_id'])['value']
res.update({
'partner_id': order_data['partner_id'] or False,
'origin': _("Point of Sale %s") % (session.name),
'client_order_ref': order_data['name'],
'user_id': order_data['user_id'] or False,
'order_line': [],
})
if self.env.context.get('is_pos_pricelist'):
res.update({
'pricelist_id': order_data['pricelist_id'],
})
for line_data in order_data['lines']:
res['order_line'].append([
0, False, self._prepare_order_line_field_from_pos(
line_data[2], res)])
session_obj = self.env["pos.session"]
session = session_obj.browse(order_data["pos_session_id"])
res = self.onchange_partner_id(order_data["partner_id"])["value"]
res.update(
{
"partner_id": order_data["partner_id"] or False,
"origin": _("Point of Sale %s") % (session.name),
"client_order_ref": order_data["name"],
"user_id": order_data["user_id"] or False,
"order_line": [],
}
)
if self.env.context.get("is_pos_pricelist"):
res.update(
{"pricelist_id": order_data["pricelist_id"],}
)
for line_data in order_data["lines"]:
res["order_line"].append(
[
0,
False,
self._prepare_order_line_field_from_pos(line_data[2], res),
]
)
return res
@api.model
def _prepare_order_line_field_from_pos(self, line_data, sale_order_data):
line_obj = self.env['sale.order.line']
line_obj = self.env["sale.order.line"]
res = line_obj.product_id_change(
sale_order_data['pricelist_id'], line_data['product_id'],
qty=line_data['qty'],
partner_id=sale_order_data['partner_id'])['value']
res.update({
'product_id': line_data['product_id'],
'product_uom_qty': line_data['qty'],
'discount': line_data['discount'],
'tax_id': [(6, False, res['tax_id'])],
})
if self.env.context.get('is_pos_pricelist'):
res.update({
'price_unit': line_data['price_unit'],
'tax_id': line_data['tax_ids'],
})
sale_order_data["pricelist_id"],
line_data["product_id"],
qty=line_data["qty"],
partner_id=sale_order_data["partner_id"],
)["value"]
res.update(
{
"product_id": line_data["product_id"],
"product_uom_qty": line_data["qty"],
"discount": line_data["discount"],
"tax_id": [(6, False, res["tax_id"])],
}
)
if self.env.context.get("is_pos_pricelist"):
res.update(
{
"price_unit": line_data["price_unit"],
"tax_id": line_data["tax_ids"],
}
)
return res
@api.model
def create_order_from_pos(self, order_data):
is_pos_pricelist = len(self.env['ir.module.module'].search(
[('name', '=', 'pos_pricelist'), ('state', '=', 'installed')]))
is_pos_pricelist = len(
self.env["ir.module.module"].search(
[("name", "=", "pos_pricelist"), ("state", "=", "installed")]
)
)
# Create Draft Sale order
sale_order = self.create(
self.with_context(is_pos_pricelist=is_pos_pricelist).
_prepare_order_field_from_pos(order_data))
self.with_context(
is_pos_pricelist=is_pos_pricelist
)._prepare_order_field_from_pos(order_data)
)
# Confirm Sale Order
if order_data['sale_order_state'] in ['confirmed', 'delivered']:
if order_data["sale_order_state"] in ["confirmed", "delivered"]:
sale_order.action_button_confirm()
# mark picking as delivered
if order_data['sale_order_state'] == 'delivered':
if order_data["sale_order_state"] == "delivered":
sale_order.picking_ids.force_assign()
sale_order.picking_ids.do_transfer()
return {
'sale_order_id': sale_order.id,
"sale_order_id": sale_order.id,
}
Loading…
Cancel
Save