[IMP] connector_opencart: import comments, add group for comment review

This commit is contained in:
Jared Kipe
2021-08-02 08:46:26 -07:00
parent 88f1ca7564
commit 007a47f8f7
2 changed files with 23 additions and 0 deletions

View File

@@ -32,4 +32,9 @@ Check your taxes and fiscal positions configuration and correct them if necessar
</record>
</data>
<record id="group_order_comment_review" model="res.groups">
<field name="name">Opencart Order Comment Reviewer</field>
</record>
</odoo>

View File

@@ -61,6 +61,7 @@ class SaleOrderImportMapper(Component):
direct = [('order_id', 'external_id'),
('store_id', 'store_id'),
('comment', 'note'),
]
children = [('products', 'opencart_order_line_ids', 'opencart.sale.order.line'),
@@ -367,12 +368,29 @@ class SaleOrderImporter(Component):
**kwargs
)
def _order_comment_review(self, binding):
review_group = self.env.ref('connector_opencart.group_order_comment_review', raise_if_not_found=False)
if review_group and binding.note:
activity_type = self.env.ref('mail.mail_activity_data_todo', raise_if_not_found=False)
activity_type_id = activity_type.id if activity_type else False
for user in review_group.users:
self.env['mail.activity'].create({
'activity_type_id': activity_type_id,
'summary': 'Order Comment Review',
'note': '<p>' + binding.note + '</p>', # field is HTML, note is expected to be escaped
'user_id': user.id,
'res_id': binding.odoo_id.id,
'res_model_id': self.env.ref('sale.model_sale_order').id,
})
def _create(self, data):
binding = super(SaleOrderImporter, self)._create(data)
# Without this, it won't map taxes with the fiscal position.
if binding.fiscal_position_id:
binding.odoo_id._compute_tax_id()
self._order_comment_review(binding)
return binding
def _import_dependencies(self):