Skip to content

Commit bfd925d

Browse files
⚡ order splitting
1 parent c3461f5 commit bfd925d

File tree

7 files changed

+118
-52
lines changed

7 files changed

+118
-52
lines changed

website_multi_company_separate_orders/controllers/main.py

+19-16
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def _check_and_update_child_order(self, sale_order, product_id, add_qty, set_qty
2424
product_company_id = product_id.company_id.id
2525
order_company = sale_order.company_id
2626
website_id = sale_order.website_id
27-
if not website_id.order_duplicating or not \
27+
if not website_id.split_orders or not \
2828
(product_company_id and product_company_id != order_company.id and
29-
(product_company_id in website_id.order_duplicating_companies.ids or force or (not add_qty and set_qty == 0))):
29+
(product_company_id in website_id.split_orders_companies.ids or force or (not add_qty and set_qty == 0))):
3030
return False
3131
sale_order_child = sale_order.order_child_ids.filtered(lambda so: so.company_id.id == product_company_id)
3232
if not sale_order_child:
@@ -45,14 +45,14 @@ def _check_and_update_child_order(self, sale_order, product_id, add_qty, set_qty
4545
_logger.info("website_sale created new child order for company: %s for order: %s",
4646
product_company_id, sale_order.id)
4747

48-
if set_qty == 0 and not add_qty:
49-
deleted_order_lines = sale_order_child.order_line.filtered(lambda ol: ol.product_id == product_id)
50-
deleted_order_lines.unlink()
51-
return sale_order_child
48+
# if set_qty == 0 and not add_qty:
49+
# deleted_order_lines = sale_order_child.order_line.filtered(lambda ol: ol.product_id == product_id)
50+
# deleted_order_lines.unlink()
51+
# return sale_order_child
52+
5253
product_custom_attribute_values = None
5354
if kw.get('product_custom_attribute_values'):
5455
product_custom_attribute_values = json.loads(kw.get('product_custom_attribute_values'))
55-
5656
no_variant_attribute_values = None
5757
if kw.get('no_variant_attribute_values'):
5858
no_variant_attribute_values = json.loads(kw.get('no_variant_attribute_values'))
@@ -64,39 +64,42 @@ def _check_and_update_child_order(self, sale_order, product_id, add_qty, set_qty
6464
product_custom_attribute_values=product_custom_attribute_values,
6565
no_variant_attribute_values=no_variant_attribute_values
6666
)
67+
sale_order.order_line.filtered(lambda ol: ol.product_id == product_id).unlink()
6768
return sale_order_child
6869

6970
@http.route()
7071
def cart_update(self, product_id, add_qty=1, set_qty=0, **kw):
7172
result = super(WebsiteSaleExtended, self).cart_update(product_id, add_qty, set_qty, **kw)
7273

73-
sale_order = request.website.sale_get_order()
74-
prod_id = request.env['product.product'].browse(int(product_id))
75-
self._check_and_update_child_order(sale_order, prod_id, add_qty, set_qty, **kw)
74+
if add_qty:
75+
sale_order = request.website.sale_get_order()
76+
prod_id = request.env['product.product'].browse(int(product_id))
77+
self._check_and_update_child_order(sale_order, prod_id, add_qty, set_qty, **kw)
7678

7779
return result
7880

7981
@http.route()
8082
def cart_update_json(self, product_id, line_id=None, add_qty=None, set_qty=None, display=True):
8183
result = super(WebsiteSaleExtended, self).cart_update_json(product_id, line_id, add_qty, set_qty, display)
8284

83-
sale_order = request.website.sale_get_order()
84-
prod_id = request.env['product.product'].browse(int(product_id))
85-
self._check_and_update_child_order(sale_order, prod_id, add_qty, set_qty)
85+
if set_qty:
86+
sale_order = request.website.sale_get_order()
87+
prod_id = request.env['product.product'].browse(int(product_id))
88+
self._check_and_update_child_order(sale_order, prod_id, add_qty, set_qty)
8689

8790
return result
8891

89-
@http.route(['/shop/duplicate_orders_for_daughter_companies/<int:company_id>'],
92+
@http.route(['/shop/split_order_for_daughter_companies/<int:company_id>'],
9093
type='json', auth="public", methods=['POST'], website=True, csrf=False)
91-
def duplicate_orders_for_daughter_companies(self, company_id=False):
94+
def split_order_for_daughter_companies(self, company_id=False):
9295
order = request.website.sale_get_order()
9396
lines = order.order_line.filtered(lambda ol: ol.product_id.company_id.id == company_id)
9497
if not lines:
9598
return False
9699
result = []
97100
for line in lines:
98101
prod = line.product_id
99-
result.append(self._check_and_update_child_order(order, prod, False, line.product_uom_qty, 'Force'))
102+
result.append(self._check_and_update_child_order(order, prod, line.product_uom_qty, False, 'Force'))
100103
return all(result)
101104

102105

website_multi_company_separate_orders/models/sale_order.py

+23-23
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,26 @@ def write(self, values):
4848
return result
4949

5050

51-
class AccountInvoice(models.Model):
52-
_inherit = 'account.invoice'
53-
54-
@api.multi
55-
def register_payment(self, payment_line, writeoff_acc_id=False, writeoff_journal_id=False):
56-
result = super(AccountInvoice, self).register_payment(payment_line, writeoff_acc_id, writeoff_journal_id)
57-
for record in self:
58-
if record.state != 'paid':
59-
return result
60-
sale_line_ids = record.invoice_line_ids[0].sale_line_ids
61-
if sale_line_ids:
62-
order = sale_line_ids[0].order_id.sudo()
63-
children = order.order_child_ids.filtered(lambda o: o.invoice_status not in ['cancel', 'invoiced'])
64-
if children:
65-
children.action_cancel()
66-
parent = order.order_parent_id
67-
if parent:
68-
product_ids = order.order_line.mapped(lambda ol: ol.product_id.id)
69-
order_line_ids = parent.order_line.filtered(lambda ol: ol.product_id.id in product_ids)
70-
order_line_ids.write({
71-
'product_uom_qty': 0,
72-
})
73-
return result
51+
# class AccountInvoice(models.Model):
52+
# _inherit = 'account.invoice'
53+
#
54+
# @api.multi
55+
# def register_payment(self, payment_line, writeoff_acc_id=False, writeoff_journal_id=False):
56+
# result = super(AccountInvoice, self).register_payment(payment_line, writeoff_acc_id, writeoff_journal_id)
57+
# for record in self:
58+
# if record.state != 'paid':
59+
# return result
60+
# sale_line_ids = record.invoice_line_ids[0].sale_line_ids
61+
# if sale_line_ids:
62+
# order = sale_line_ids[0].order_id.sudo()
63+
# children = order.order_child_ids.filtered(lambda o: o.invoice_status not in ['cancel', 'invoiced'])
64+
# if children:
65+
# children.action_cancel()
66+
# parent = order.order_parent_id
67+
# if parent:
68+
# product_ids = order.order_line.mapped(lambda ol: ol.product_id.id)
69+
# order_line_ids = parent.order_line.filtered(lambda ol: ol.product_id.id in product_ids)
70+
# order_line_ids.write({
71+
# 'product_uom_qty': 0,
72+
# })
73+
# return result

website_multi_company_separate_orders/models/website.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
class Website(models.Model):
1414
_inherit = "website"
1515

16-
order_duplicating = fields.Boolean(string='Automatic Order Duplicating',
17-
help='Duplicate orders for Daughter companies')
18-
order_duplicating_companies = fields.Many2many('res.company', string='Order Duplicating Companies',
16+
split_orders = fields.Boolean(string='Automatic Order Splitting',
17+
help='Split orders for Daughter companies')
18+
split_orders_companies = fields.Many2many('res.company', string='Order Duplicating Companies',
1919
help='Daughter companies where order is being automatically duplicated to')
2020

2121
@api.model
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
.separate_order {
2-
cursor:pointer;
32
color: #00A09D;
4-
text-decoration:underline;
53
font-size: 13px;
64
}
5+
6+
.separate_order:not(.child_order) {
7+
cursor:pointer;
8+
text-decoration:underline;
9+
}

website_multi_company_separate_orders/static/src/js/website_cart.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ var sAnimations = require('website.content.snippets.animation');
99
sAnimations.registry.WebsiteSale.include({
1010

1111
read_events: _.extend(sAnimations.registry.WebsiteSale.prototype.read_events, {
12-
'click td.td-product_name .separate_order': '_duplicate_order_request',
12+
'click td.td-product_name .separate_order:not(.child_order)': '_duplicate_order_request',
1313
}),
1414

1515
_duplicate_order_request: function(event) {
1616
var cid = event.target.attributes.pcid.value;
1717
if (!cid) {
1818
return;
1919
}
20-
session.rpc("/shop/duplicate_orders_for_daughter_companies/" + cid, {})
20+
session.rpc("/shop/split_order_for_daughter_companies/" + cid, {})
2121
.then(function(result) {
2222
if (result) {
23-
alert('Order was duplicated');
23+
// alert('Order was duplicated');
24+
location.reload();
2425
}
2526
});
2627
},

website_multi_company_separate_orders/views/templates.xml

+61-2
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,78 @@
33
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -->
44
<odoo>
55
<template id="cart_lines" name="duplicate order assets" inherit_id="website_sale.cart_lines">
6+
7+
<!-- <xpath expr="//div[hasclass('oe_cart')]" position="before">-->
8+
<!-- <div class="col-12">-->
9+
<!-- Since the items in your shopping cart belong to different companies, please place an order separately-->
10+
<!-- </div>-->
11+
<!-- </xpath>-->
12+
613
<xpath expr="//td[hasclass('td-product_name')]/div" position="after">
714
<t t-set="order_company" t-value="website_sale_order.company_id"/>
815
<t t-set="product_company_id" t-value="line.product_id.company_id.id"/>
916
<t t-set="website_id" t-value="website_sale_order.website_id"/>
10-
<t t-if="website_id.order_duplicating and
17+
<t t-if="website_id.split_orders and
1118
order_company.id != product_company_id and
1219
product_company_id in order_company.child_ids.ids and
13-
product_company_id not in website_sale_order.website_id.order_duplicating_companies.ids">
20+
product_company_id not in website_sale_order.website_id.split_orders_companies.ids">
1421
<div class="separate_order" t-attf-pcid="{{product_company_id}}">
1522
(duplicate order to <t t-esc="line.product_id.company_id.name"/>)
1623
</div>
1724
</t>
1825
</xpath>
26+
27+
<xpath expr="//tbody" position="inside">
28+
<t t-set="child_lines" t-value="website_sale_order.order_child_ids.mapped('website_order_line')"/>
29+
<t t-foreach="child_lines" t-as="line">
30+
<tr t-att-class="'optional_product info' if line.linked_line_id else None" style="opacity: 0.5;">
31+
<td colspan="2" t-if="not line.product_id.product_tmpl_id" class='td-img'></td>
32+
<td align="center" t-if="line.product_id.product_tmpl_id" class='td-img'>
33+
<span t-field="line.product_id.image_small" t-options="{'widget': 'image', 'class': 'rounded'}" />
34+
</td>
35+
<td t-if="line.product_id.product_tmpl_id" class='td-product_name'>
36+
<div>
37+
<t t-call="website_sale.cart_line_product_link">
38+
<strong t-field="line.name_short" />
39+
</t>
40+
</div>
41+
<div>
42+
<div class="separate_order child_order">
43+
(<t t-esc="line.order_id.company_id.name"/>)
44+
</div>
45+
</div>
46+
<t t-call="website_sale.cart_line_description_following_lines">
47+
<t t-set="div_class" t-value="'d-none d-md-block'"/>
48+
</t>
49+
</td>
50+
<td class="text-center td-qty">
51+
<div t-if="not line.linked_line_id" class="css_quantity input-group mx-auto oe_website_spinner">
52+
<input readonly="True" type="text" class="js_quantity form-control quantity" t-att-data-line-id="line.id" t-att-data-product-id="line.product_id.id" t-att-value="int(line.product_uom_qty) == line.product_uom_qty and int(line.product_uom_qty) or line.product_uom_qty" />
53+
</div>
54+
<t t-if="line.linked_line_id">
55+
<span class="js_quantity text-muted" t-att-data-line-id="line.id" t-att-data-product-id="line.product_id.id" t-esc="int(line.product_uom_qty)"/>
56+
</t>
57+
</td>
58+
<td class="text-center td-price" name="price">
59+
<t t-set="combination" t-value="line.product_id.product_template_attribute_value_ids + line.product_no_variant_attribute_value_ids"/>
60+
<t t-set="combination_info" t-value="line.product_id.product_tmpl_id._get_combination_info(combination)"/>
61+
62+
<t t-set="list_price_converted" t-value="website.currency_id._convert(combination_info['list_price'], website_sale_order.currency_id, website_sale_order.company_id, date)"/>
63+
<t groups="account.group_show_line_subtotals_tax_excluded" t-if="(website_sale_order.pricelist_id.discount_policy == 'without_discount' and website_sale_order.currency_id.compare_amounts(list_price_converted, line.price_reduce_taxexcl) == 1) or website_sale_order.currency_id.compare_amounts(line.price_unit, line.price_reduce) == 1" name="order_line_discount">
64+
<del t-attf-class="#{'text-danger mr8'}" style="white-space: nowrap;" t-esc="list_price_converted" t-options="{'widget': 'monetary', 'display_currency': website_sale_order.currency_id}" />
65+
</t>
66+
<span t-field="line.price_reduce_taxexcl" style="white-space: nowrap;" t-options="{'widget': 'monetary', 'display_currency': website_sale_order.currency_id}" groups="account.group_show_line_subtotals_tax_excluded" />
67+
<t groups="account.group_show_line_subtotals_tax_included" t-if="(website_sale_order.pricelist_id.discount_policy == 'without_discount' and website_sale_order.currency_id.compare_amounts(list_price_converted, line.price_reduce_taxinc) == 1) or website_sale_order.currency_id.compare_amounts(line.price_unit, line.price_reduce) == 1" name="order_line_discount">
68+
<del t-attf-class="#{'text-danger mr8'}" style="white-space: nowrap;" t-esc="list_price_converted" t-options="{'widget': 'monetary', 'display_currency': website_sale_order.currency_id}" />
69+
</t>
70+
<span t-field="line.price_reduce_taxinc" style="white-space: nowrap;" t-options="{'widget': 'monetary', 'display_currency': website_sale_order.currency_id}" groups="account.group_show_line_subtotals_tax_included" />
71+
</td>
72+
<td class="td-action">
73+
</td>
74+
</tr>
75+
</t>
76+
</xpath>
77+
1978
</template>
2079

2180
<template id="assets_frontend" inherit_id="website.assets_frontend" name="Shop Cart">

website_multi_company_separate_orders/views/website_views.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
<field name="inherit_id" ref="website.view_website_form"/>
1010
<field name="arch" type="xml">
1111
<xpath expr="//field[@name='default_lang_id']" position="after">
12-
<field name="order_duplicating"/>
13-
<field name="order_duplicating_companies"
14-
attrs="{'invisible': [('order_duplicating', '=', False)]}"
12+
<field name="split_orders"/>
13+
<field name="split_orders_companies"
14+
attrs="{'invisible': [('split_orders', '=', False)]}"
1515
widget="many2many_tags"/>
1616
</xpath>
1717
</field>

0 commit comments

Comments
 (0)